当前位置:首页 > 科学课件 > 正文内容

数据结构课程设计

zhao_admin12个月前 (06-03)科学课件54

#include #include #include #include #define MAXSIZE 100 typedef struct Ttime{ int t_hour; int t_min; int t_sec; }Ttime; typedef struct Mcar{ int number; Ttime t[2]; }Mcar; typedef struct{ Mcar elements[MAXSIZE]; int top; }CarStop; typedef struct node{ Mcar date; struct node *next; }LinkQueue; typedef struct{ LinkQueue *front; LinkQueue *rear; }Queue; void InitQueue(Queue *Q){ Q -> front = (LinkQueue *) malloc(sizeof(LinkQueue)); Q -> front -> next = NULL; Q -> rear = Q -> front; } int IsEmptyH(Queue Q){ if(Q.front == Q.rear) return 1; else return 0; } void EeQueue(Queue *Q, Mcar x){ Q -> rear -> next = (LinkQueue *)malloc(sizeof(LinkQueue)); Q -> rear = Q -> rear -> next; Q -> rear -> date = x; Q -> rear -> next = NULL; } Mcar DeQueue(Queue *Q){ LinkQueue *p; Mcar y; if(!IsEmpty(*Q)){ p = Q -> front -> next; Q -> front -> next = p -> next; if(p -> next == NULL) Q -> rear = Q -> front; y = p -> date; free(p); return y; } } int IsEmpty(CarStop S){ if(S.top == 0) return 1; else return 0; } int IsFull(CarStop S){ if(S.top == MAXSIZE) return 1; else return 0; } int Init(CarStop *S){ S -> top = 0; } void PutIn(CarStop *S, Mcar D){ if(!IsFull(*S)){ S -> elements[S -> top] = D; S -> top++; } else printf(IS FULL); } Mcar Pop(CarStop *S){ if(!IsEmpty(*S)){ S -> top--; return S -> elements[S -> top]; } else printf(IS NULL); } Mcar TopNum(CarStop S){ if(!IsEmpty(S)){ return S.elements[S.top - 1]; } } int serachOneCar(CarStop S, Mcar num){ int i = 0; if(!IsEmpty(S)){ while(i tm_hour; car.t[0].t_min = tmptr -> tm_min; car.t[0].t_sec = tmptr -> tm_sec; printf(please put in you car number:n); scanf(%d, &car.number); if(!IsFull(*CarStack)) PutIn(CarStack, car); else{ printf(car stop is full, please stay in biandaon); EeQueue(Q, car); } printf(you car's intime is :[%d]:[%d]:[%d]nnn, car.t[0].t_hour, car.t[0].t_min, car.t[0].t_sec); } void getOutOneCar(CarStop *CarStack, CarStop *CarStackL, Queue *Q, Mcar car){ Mcar lin; time_t secnow; struct tm * tmptr; time(&secnow); tmptr = localtime(&secnow); car.t[1].t_hour= tmptr -> tm_hour; car.t[1].t_min = tmptr -> tm_min; car.t[1].t_sec = tmptr -> tm_sec; printf(please put in you car number:n); scanf(%d, &car.number); if(IsEmpty(*CarStack) || !serachOneCar(*CarStack, car)) printf(soory, there is no the carn); else{ while(1){ lin = Pop(CarStack); if(lin.number == car.number) break; else PutIn(CarStackL, lin); } while(!IsEmpty(*CarStackL)){ PutIn(CarStack, Pop(CarStackL)); } if(!IsEmptyH(*Q)) PutIn(CarStack, DeQueue(Q)); printf(nnyou car's intime is :[%d]:[%d]:[%d]n, lin.t[0].t_hour, lin.t[0].t_min, lin.t[0].t_sec); printf(you car's out time is :[%d]:[%d]:[%d]n, car.t[1].t_hour, car.t[1].t_min, car.t[1].t_sec); int alltime = (car.t[1].t_hour - lin.t[0].t_hour) * 3600 + (car.t[1].t_min - lin.t[0].t_min) * 60 + (car.t[1].t_sec - lin.t[0].t_sec); printf(you car's all time is second:[%d]n, alltime); } } int main(){ CarStop CarStack, CarStackL; Queue Q; LinkQueue *pp; InitQueue(&Q); Init(&CarStack); Init(&CarStackL); Mcar car; //String caozuo; int caozuo, i, j; while(1){ printf(t**************the car stop menu*************n); printf(tt***** 1. get in a carnn); printf(tt***** 2. get out a carnn); printf(tt***** 0. out the car stopnn); printf(tt*****put in the else you can see all the car in the carstopnn); printf(t*****************************************n); printf(please put in you caozuo: n); scanf(%d, &caozuo); switch(caozuo){ case 1: getInOneCar(&CarStack, &Q, car); break; case 2: getOutOneCar(&CarStack, &CarStackL, &Q, car); break; case 0: return 0; break; default : break; } if(!IsEmpty(CarStack)){ i = 0; printf(the all car is:n); while(i next -> date.number); pp = pp -> next; j++; } } else printf(the biandao is NULLn); printf(****************************n); system(pause); system(cls); } } C语言编译通过

扫描二维码推送至手机访问。

版权声明:本文由PPT写作技巧发布,如需转载请注明出处。

本文链接:http://www.ppt3000.com/post/67147.html

分享给朋友:

相关文章