永发信息网

数据结构课程设计

答案:1  悬赏:70  手机版
解决时间 2021-10-12 11:50
数据结构课程设计
最佳答案
#include <stdio.h>#include <malloc.h>#include <windows.h>#include <time.h>#define MAXSIZE 100typedef 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 <= S.top){ if(num.number == S.elements[i].number) return 1; i++; } } else return 0;}void getInOneCar(CarStop *CarStack, Queue *Q, Mcar car){ time_t secnow; struct tm * tmptr; time(&secnow); tmptr = localtime(&secnow); car.t[0].t_hour= tmptr -> 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 biandao\n"); EeQueue(Q, car); } printf("you car's intime is :[%d]:[%d]:[%d]\n\n\n", 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 car\n"); 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("\n\nyou 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("\t\t***** 1. get in a car\n\n"); printf("\t\t***** 2. get out a car\n\n"); printf("\t\t***** 0. out the car stop\n\n"); printf("\t\t*****put in the else you can see all the car in the carstop\n\n"); 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 < CarStack.top){ printf("the [%d] is %d\n",i + 1, CarStack.elements[i].number); i++; } } else printf("the car stop IS NULL\n"); printf("****************************\n"); if(!IsEmptyH(Q)){ j = 1; pp=Q.front; printf("the biandao's car is:\n"); while(pp!=Q.rear){ printf("the [%d] wait car is %d\n", j, pp -> next -> date.number); pp = pp -> next; j++; } } else printf("the biandao is NULL\n"); printf("****************************\n"); system("pause"); system("cls"); }}C语言编译通过
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
郑州学汽车修理到哪里好?
请告诉我哪里可以买到斗牛犬?
三星xqb50-l75怎么拆洗内桶,有什么方法?
男朋友帮女性朋友带狗,今天他朋友要去他家拿
南阳理工学院选修课挂了3科怎么办?(今年6月毕
广东席子厂哪家好?有谁清楚?
液晶电视机的工作原理及组件,越详细越好,谢
我想要Ella的照片
怎样才能挽回老婆离婚后决绝的心
看哪位网友知道酒店房间装修风格有哪些?
请问户外隔离开关gw9乐清市哪家做的好?
笔记本电脑按键不灵是怎么回事
321沙发套常用的尺寸有多大?
贝泉保湿去角质脚膜怎么用去皮效果最好呢?
什么是工程初步验收?有哪位知道?
推荐资讯
专家说一下客厅挂的钟表有什么风水讲究吗?主
请问塑钢玻璃门价格如何?
大母脚趾甲颜色突然变紫是怎么会事
中考作文\"说说我自己\"开头怎么写
哪里有吃海鲜的地方,介绍
哈尔滨万路机动车检测有限公司地址有知道的么
叶璇主演的最新的电视剧
室内设计中,玻璃和和镜面用什么连接好?
如何辨别深圳健康证的真假
耳朵发热是怎么回事?
安徽马鞍山购房契税需要交多少?谁知道这个
现代简约洗手间装修有什么元素?流程怎么走?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?