该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
/*------------------------------------------------------------------------------*/
#define MAX 2 /*车库容量*/
#define price 0.05 /*每车每分钟费用*/
typedef struct time{
int hour;
int min;
}Time; /*时间结点*/
typedef struct node{
char num[10];
Time reach;
Time leave;
}CarNode; /*车辆信息结点*/
typedef struct NODE{
CarNode *stack[MAX+1];
int top;
}SeqStackCar; /*模拟车站*/
typedef struct car{
CarNode *data;
struct car *next;
}QueueNode;
typedef struct Node{
QueueNode *head;
QueueNode *rear;
}LinkQueueCar; /*模拟通道*/
/*------------------------------------------------------------------------------*/
void InitStack(SeqStackCar *); /*初始化栈*/
int InitQueue(LinkQueueCar *); /*初始化便道*/
int Arrival(SeqStackCar *,LinkQueueCar *); /*车辆到达*/
void Leave(SeqStackCar *,SeqStackCar *,LinkQueueCar *); /*车辆离开*/
void List(SeqStackCar,LinkQueueCar); /*显示存车信息*/
/*------------------------------------------------------------------------------*/
void main()
{
SeqStackCar Enter,Temp;
LinkQueueCar Wait;
int ch;
InitStack(&Enter); /*初始化车站*/
InitStack(&Temp); /*初始化让路的临时栈*/
InitQueue(&Wait); /*初始化通道*/
while(1)
{
printf("\n1. the car arrive");
printf(" 2. the car leave");
printf(" 3. the schedule ");
printf(" 4. out\n");
while(1)
{
scanf("%d",&ch);
if(ch>=1&&ch<=4)break;
else printf("\nplease choose: 1|2|3|4.");
}
switch(ch)
{
case 1:Arrival(&Enter,&Wait);break; /*车辆到达*/
case 2:Leave(&Enter,&Temp,&Wait);break; /*车辆离开*/
case 3:List(Enter,Wait);break; /*列表打印信息*/
case 4:exit(0); /*退出主程序*/
default: break;
}
}
}
/*------------------------------------------------------------------------------*/
void InitStack(SeqStackCar *s) /*初始化栈*/
{
int i;
s->top=0;
for(i=0;i<=MAX;i++)
s->stack[s->top]=NULL;
}
int InitQueue(LinkQueueCar *Q) /*初始化便道*/
{
Q->head=(QueueNode *)malloc(sizeof(QueueNode));
if(Q->head!=NULL)
{
Q->head->next=NULL;
Q->rear=Q->head;
return(1);
}
else return(-1);
}
void PRINT(CarNode *p,int room) /*打印出站车的信息*/
{
int A1,A2,B1,B2;
printf("\nplease input thedepart time:/**:**/");
scanf("%d:%d",&(p->leave.hour),&(p->leave.min));
printf("\nthe number of the car:");
puts(p->num);
printf("\nthe time the car arrive: %d:%d",p->reach.hour,p->reach.min);
printf("the depart time: %d:%d",p->leave.hour,p->leave.min);
A1=p->reach.hour;
A2=p->reach.min;
B1=p->leave.hour;
B2=p->leave.min;
printf("\nthe fee: %2.1f元",((B1-A1)*60+(B2-A2))*price);
free(p);
}
int Arrival(SeqStackCar *Enter,LinkQueueCar *W) /*车辆到达*/
{
CarNode *p;
QueueNode *t;
p=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("\ninput the number of the car(例:陕A1234):");
gets(p->num);
if(Enter->top
{
Enter->top++;
printf("\nthe place of the car.",Enter->top);
printf("\nthe time thecar arrive:/**:**/");
scanf("%d:%d",&(p->reach.hour),&(p->reach.min));