功能:
默认了最大车位3个
车牌号在10个字符以内
停车场满了进入辅助车道
出车借助辅助停车场实现了全车位出车
随时查看停车状态
更新:
参考了网上的函数
更新了界面,更新了进出车方式
为了保留最大信息,还原网上数据结构的大部分注释,保存最原始代码
优化错误判断,优化界面,优化注释
主函数:
main.c
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include "display.h" 5 #include "structure.h" 6 #include "function.h" 7 8 int main() 9 { 10 Stack park,temp_park; 11 Queue wait_line; 12 int tag;//for choose menu operation 13 14 /////////////////INIT STRUCTURE/////////////////// 15 InitStack(&park); 16 InitStack(&temp_park); 17 InitQueue(&wait_line); 18 ///////////////////////////////////////////////// 19 20 display_welcome(); 21 int flag=1;//position of choose 22 while(flag) 23 { 24 display_menu(); 25 scanf("%d",&tag); 26 if(tag<1||tag>4)//judge correction 27 { 28 display_error_number();break; 29 } 30 switch(tag) 31 { 32 case 1 :Arrival(&park,&wait_line);break; 33 case 2 :Leave(park,temp_park,wait_line);break; 34 case 3 :List(park,wait_line);break; 35 case 4 :exit(0); 36 default : flag=0;break; 37 } 38 display_menu(); 39 } 40 return 0; 41 }
显示函数:
display.h
1 #ifndef DISPLAY_H 2 #define DISPLAY_H 3 4 void display_welcome(); 5 void display_menu(); 6 void display_arrive_menu(); 7 void display_arrive_unfull(); 8 void display_arrive_full(); 9 void display_leave_menu(); 10 void display_leave_car_info(); 11 void display_leave_park_menu(); 12 void display_leave_line_to_park(); 13 void display_leave_line_menu(); 14 void display_list_menu(); 15 void display_list_park(); 16 void display_list_line();//welcome menun 17 void display_line_menu();//welcome menun 18 void display_park_menu(); 19 void display_error_number(); 20 void display_uncar_line(); 21 void display_uncar_park(); 22 #endif
display.c
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include "display.h" 5 #include "structure.h" 6 ////////////////////////////////////////////////////////////////////////////// 7 8 void display_welcome() 9 { 10 printf("this is parking system "); 11 printf("you can enter any key to continue "); 12 getchar(); 13 system("cls"); 14 } 15 16 /////////////////////////////////////////////////////////////////////////////// 17 18 /////////////////////////////////////////////////////////////////////////////// 19 void display_menu() 20 { 21 printf("************************************************** "); 22 printf("* welcome to parking system * "); 23 printf("* menu: * "); 24 printf("* enter 1 to creat a car to parking * "); 25 printf("* enter 2 to leave a car from system * "); 26 printf("* enter 3 to listing all car position * "); 27 printf("* enter 4 to exit system * "); 28 printf("************************************************** "); 29 } 30 31 //////////////////////////////////////////////////////////////////////////// 32 33 ///////////////////////////////////////////////////////////////////////////// 34 void display_arrive_menu(Elemtype *e) 35 { 36 printf("************************************************** "); 37 printf("* please enter car number like :BMW99: * "); 38 printf(" "); 39 scanf("%s",e->num); 40 printf("************************************************** "); 41 } 42 43 //////////////////////////////////////////////////////////////////////////////// 44 45 //////////////////////////////////////////////////////////////////////////////// 46 47 void display_arrive_unfull(int count) 48 { 49 printf("************************************************** "); 50 printf("* car is parking in NO.%d lacation * ",count); 51 printf("************************************************** "); 52 } 53 54 //////////////////////////////////////////////////////////////////////////// 55 56 /////////////////////////////////////////////////////////////////////////// 57 58 void display_arrive_full() 59 { 60 printf("************************************************** "); 61 printf("* park is in full,car in wating line * "); 62 printf("************************************************** "); 63 } 64 65 ////////////////////////////////////////////////////////////////////////////// 66 67 ////////////////////////////////////////////////////////////////////////////// 68 69 void display_leave_menu() 70 { 71 printf("************************************************** "); 72 printf("* leave car in park or in first line * "); 73 printf("* enter 1 to leave car in park * "); 74 printf("* enter 2 to leave car in first line * "); 75 printf("* enter 3 to exit leave car * "); 76 printf("************************************************** "); 77 } 78 79 ///////////////////////////////////////////////////////////////////////////// 80 81 ////////////////////////////////////////////////////////////////////////////// 82 83 void display_error_number() 84 { 85 printf("************************************************** "); 86 printf("* error number enter again * "); 87 printf("************************************************** "); 88 } 89 90 ////////////////////////////////////////////////////////////////////////////// 91 92 ////////////////////////////////////////////////////////////////////////////// 93 94 void display_uncar_line() 95 { 96 printf("************************************************** "); 97 printf("* there is no car in the line * "); 98 printf("************************************************** "); 99 } 100 101 ////////////////////////////////////////////////////////////////////////////// 102 103 ////////////////////////////////////////////////////////////////////////////// 104 105 void display_uncar_park() 106 { 107 printf("************************************************** "); 108 printf("* there is no car in the park * "); 109 printf("************************************************** "); 110 } 111 112 ////////////////////////////////////////////////////////////////////////////// 113 114 ////////////////////////////////////////////////////////////////////////////// 115 116 void display_list_menu() 117 { 118 printf("************************************************** "); 119 printf("* please select: * "); 120 printf("* enter 1 to look all parking car * "); 121 printf("* enter 2 to look all line car * "); 122 printf("* enter 3 to exit look list system * "); 123 printf("************************************************** "); 124 } 125 126 ////////////////////////////////////////////////////////////////////////////// 127 128 ////////////////////////////////////////////////////////////////////////////// 129 130 void display_park_menu() 131 { 132 printf("************************************************** "); 133 printf("* parking listing: * "); 134 printf("************************************************** "); 135 } 136 137 ////////////////////////////////////////////////////////////////////////////// 138 139 ////////////////////////////////////////////////////////////////////////////// 140 141 void display_line_menu() 142 { 143 printf("************************************************** "); 144 printf("* line listing: * "); 145 printf("************************************************** "); 146 } 147 148 ////////////////////////////////////////////////////////////////////////////// 149 150 ////////////////////////////////////////////////////////////////////////////// 151 152 void display_leave_car_info(Elemtype *e) 153 { 154 printf(" "); 155 printf("************************************************** "); 156 printf("* car is leave,the car num is * "); 157 printf("* %s * ",e->num); 158 printf("************************************************** "); 159 } 160 ////////////////////////////////////////////////////////////////////////////// 161 162 ////////////////////////////////////////////////////////////////////////////// 163 void display_leave_park_menu(int count) 164 { 165 printf("************************************************** "); 166 printf("* parking car number is %d * ",count); 167 printf("* please choose a parking number to leave * "); 168 printf("************************************************** "); 169 } 170 171 ////////////////////////////////////////////////////////////////////////////// 172 173 ////////////////////////////////////////////////////////////////////////////// 174 175 void display_leave_line_to_park(int count,Elemtype *temp_parking) 176 { 177 printf("************************************************** "); 178 printf(" car number:%s ",temp_parking->num); 179 printf("* car is leaving line * "); 180 printf("* car is in parking No. %d location * ",count); 181 printf("************************************************** "); 182 } 183 184 ////////////////////////////////////////////////////////////////////////////// 185 186 ////////////////////////////////////////////////////////////////////////////// 187 188 void display_leave_line_menu(Elemtype *line_parking) 189 { 190 printf("************************************************** "); 191 printf(" car number is %s ",line_parking->num); 192 printf("* car is leaving line * "); 193 printf("* car leave line successful * "); 194 printf("************************************************** "); 195 } 196 197 ////////////////////////////////////////////////////////////////////////////// 198 199 ////////////////////////////////////////////////////////////////////////////// 200 201 void display_list_park(char ch[],int i) 202 { 203 printf("************************************************** "); 204 printf(" location No.%d ",i); 205 printf(" car number is %s ",ch); 206 printf("************************************************** "); 207 } 208 209 ////////////////////////////////////////////////////////////////////////////// 210 211 ////////////////////////////////////////////////////////////////////////////// 212 213 void display_list_line(char ch[]) 214 { 215 printf("************************************************** "); 216 printf(" car number is %s ",ch); 217 printf("************************************************** "); 218 } 219 220 //////////////////////////////////////////////////////////////////////////////
功能函数:
function.h
1 #ifndef FUNCTION_H 2 #define FUNCTION_H 3 void Listpark(); 4 void Listline(); 5 void List(); 6 void Leaveline(); 7 void Leavepark(); 8 int Leave(); 9 int Arrival(); 10 #endif // FUNCTION_H
function.c
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include "display.h" 5 #include "structure.h" 6 #include "function.h" 7 /////////////////////////////////////////////////////////////////////////// 8 void Listpark(Stack *S) 9 { 10 int i; 11 if(S->top>0) //judge whether car in parking 12 { 13 display_park_menu(); 14 for(i=1;i<=S->top;i++) 15 { 16 char ch[10]; 17 strcpy(ch,S->stack[i]->num); 18 display_list_park(ch,i); 19 20 } 21 } 22 else 23 { 24 display_uncar_park(); 25 } 26 } 27 ///////////////////////////////////////////////////////////////////////////////////// 28 29 void Listline(Queue *Q) //list display car of position in line 30 { 31 Line_car *p; 32 p=Q->head->next; 33 34 if(Q->head!=Q->rear) //judge whether have car in line 35 { 36 display_line_menu(); 37 while(p!=NULL) 38 { 39 40 char ch[10];//creat a string 41 strcpy(ch,p->ptr_car->num); 42 display_list_line(ch); 43 p=p->next; 44 } 45 } 46 else 47 { 48 display_uncar_line(); 49 } 50 } 51 52 ////////////////////////////////////////////////////////////////////////////// 53 54 void List(Stack S,Queue Q) 55 { 56 int flag,tag; 57 flag=1; 58 while(flag) 59 { 60 61 display_list_menu(); 62 scanf("%d",&tag); 63 switch(tag) 64 { 65 case 1:Listpark(&S);break; //listing imformation of park 66 case 2:Listline(&Q);break; //listing imformation of line 67 case 3:flag=0;break; 68 default: display_error_number();display_list_menu();break; 69 } 70 } 71 } 72 73 ////////////////////////////////////////////////////////////////////////////// 74 75 void Leavepark(Stack *S,Stack *Ts,Queue *Q) 76 { 77 78 int park_where; 79 Elemtype *parking,*temp_parking; 80 Line_car *q; 81 if(S->top>0) //if have car in park 82 { 83 while(1) //enter information of car of leave 84 { 85 Listpark(S); 86 int count=S->top; 87 display_leave_park_menu(count); 88 printf(" "); 89 scanf("%d",&park_where); 90 if(park_where>=1&&park_where<=S->top)//if uncorrection enter 91 { 92 break; 93 } 94 else 95 { 96 display_error_number(); 97 display_leave_park_menu(S); 98 printf(" "); 99 scanf("%d",&park_where); 100 } 101 } 102 while(S->top>park_where) //leave car 103 { 104 Ts->top++; 105 Ts->stack[Ts->top]=S->stack[S->top]; 106 S->stack[S->top]=NULL; 107 S->top--; 108 } 109 parking=S->stack[S->top]; 110 S->stack[S->top]=NULL; 111 S->top--; 112 while(S->top>=1) 113 { 114 S->top++; 115 S->stack[S->top]=Ts->stack[Ts->top]; 116 Ts->stack[Ts->top]=NULL; 117 Ts->top--; 118 } 119 display_leave_car_info(parking); 120 //jugde position of car in line for enter car to park from line 121 if((Q->head!=Q->rear)&&S->top<MAX)//enter car to park from line 122 { 123 q=Q->head->next; 124 temp_parking=q->ptr_car; 125 S->top++; 126 int count=S->top; 127 display_leave_line_to_park(count,temp_parking); 128 Q->head->next=q->next; 129 if(q==Q->rear) Q->rear=Q->head;//change positon of Queue stuctre 130 S->stack[S->top]=temp_parking; 131 free(q); 132 } 133 else 134 { 135 display_uncar_line(); 136 } 137 } 138 else 139 { 140 display_uncar_park(); 141 } 142 } 143 //////////////////////////////////////////////////////////// 144 145 void Leaveline(Queue *Q)//only fisrt car in line permitted leave 146 { 147 Line_car *q; 148 Elemtype *line_parking; 149 if(Q->head!=Q->rear) 150 { 151 q=Q->head->next; 152 line_parking=q->ptr_car; 153 display_leave_line_menu(line_parking); 154 Q->head->next=q->next; 155 if(q==Q->rear) Q->rear=Q->head;//change Queue position 156 free(q); 157 } 158 else 159 { 160 display_uncar_line(); 161 } 162 } 163 164 //////////////////////////////////////////////////////////// 165 166 int Leave(Stack S,Stack Ts,Queue Q)//toatal leave function that linked with two choice 167 { 168 int i; 169 while(1) 170 { 171 display_leave_menu(); 172 while(1) 173 { 174 scanf("%d",&i); 175 switch(i)//menue 176 { 177 case 1 :Leavepark(&S,&Ts,&Q);break; 178 case 2 :Leaveline(&Q);break; 179 case 3 :return 0; 180 default : display_error_number();break; 181 } 182 display_leave_menu(); 183 } 184 } 185 return 0; 186 } 187 188 ////////////////////////////////////////////////////////////// 189 190 int Arrival(Stack *S,Queue *Q) 191 { 192 Elemtype *e; 193 Line_car *q; 194 e=(Elemtype*)malloc(sizeof(Elemtype)); 195 fflush(stdin); 196 display_arrive_menu(e); 197 if(S->top<MAX) //parking is unfull,car into parking 198 { 199 S->top++; 200 int count; 201 count=S->top; 202 display_arrive_unfull(count); 203 S->stack[S->top]=e; 204 return(1); 205 } 206 else //parking is full,car into line 207 { 208 display_arrive_full(); 209 q=(Line_car*)malloc(sizeof(Line_car)); 210 q->ptr_car=e; 211 q->next=NULL; 212 Q->rear->next=q; 213 Q->rear=q; 214 return(1); 215 } 216 } 217 218 ////////////////////////////////////////////////////////////////
结构体函数:
structure.h
1 #ifndef STRUCTURE_H 2 #define STRUCTURE_H 3 #define MAX 3 4 typedef struct 5 { 6 char num[10]; 7 }Elemtype;//information of Car 8 9 typedef struct 10 { 11 Elemtype *stack[MAX+1]; 12 int top; 13 }Stack;//paking structure 14 15 typedef struct 16 { 17 Elemtype *ptr_car; 18 struct Line_car *next; 19 }Line_car;//car in line structure 20 21 typedef struct 22 { 23 Line_car *head; 24 Line_car *rear; 25 }Queue;//waiting line structure 26 27 void InitStack(); 28 int InitQueue(); 29 30 #endif
structure.c
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include "structure.h" 5 ////////////////////////////////////////////////////////////////////////////// 6 7 void InitStack(Stack *S) 8 { 9 int i; 10 S->top=0; 11 for(i=0;i<=MAX;i++) 12 S->stack[S->top]=NULL; 13 } 14 15 ////////////////////////////////////////////////////////////////////////////// 16 17 int InitQueue(Queue *Q) 18 { 19 Q->head=malloc(sizeof(Queue)); 20 if(Q->head!=NULL) 21 { 22 Q->head->next=NULL; 23 Q->rear=Q->head; 24 return(1); 25 } 26 else return(-1); 27 } 28 29 //////////////////////////////////////////////////////////////////////////////
最原始代码:
2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include "display.h" 6 #define MAX 3//store paking 7 8 typedef struct 9 { 10 char num[10]; 11 }Elemtype;//information of Car 12 13 typedef struct 14 { 15 Elemtype *stack[MAX+1]; 16 int top; 17 }Stack;//paking station 18 19 typedef struct 20 { 21 Elemtype *ptr_car; 22 struct Line_car *next; 23 }Line_car; 24 25 typedef struct 26 { 27 Line_car *head; 28 Line_car *rear; 29 }Queue;//waiting line 30 31 void InitStack(Stack *); 32 int InitQueue(Queue *); 33 int Arrival(Stack *,Queue *); 34 void Leaveline(Queue *Q); 35 void Leavepark(Stack *S,Stack *Ts,Queue *Q); 36 int Leave(Stack ,Stack ,Queue ); 37 void Listpark(Stack *S); 38 void List(Stack ,Queue ); 39 40 int main() 41 { 42 Stack park,temp_park; 43 Queue wait_line; 44 int select; 45 InitStack(&park); 46 InitStack(&temp_park); 47 InitQueue(&wait_line); 48 printf("this is parking system "); 49 printf("you can enter any key to continue "); 50 getch(); 51 system("cls"); 52 while(1) 53 { 54 printf("************************************************** "); 55 printf("* welcome to parking system * "); 56 printf("* menu: * "); 57 printf("* enter 1 to creat a car to parking * "); 58 printf("* enter 2 to leave a car from system * "); 59 printf("* enter 3 to listing all car position * "); 60 printf("* enter 4 to exit system * "); 61 printf("************************************************** "); 62 while(1) 63 { 64 scanf("%d",&select); 65 if(select<1||select>4) 66 { 67 printf("error number enter again ");break; 68 } 69 switch(select) 70 { 71 case 1 :Arrival(&park,&wait_line);break; 72 case 2 :Leave(park,temp_park,wait_line);break; 73 case 3 :List(park,wait_line);break; 74 case 4 :exit(0); 75 default : break; 76 } 77 printf("************************************************** "); 78 printf("* welcome to parking system * "); 79 printf("* menu: * "); 80 printf("* enter 1 to creat a car to parking * "); 81 printf("* enter 2 to leave a car from system * "); 82 printf("* enter 3 to listing all car position * "); 83 printf("* enter 4 to exit system * "); 84 printf("************************************************** "); 85 } 86 } 87 return 0; 88 } 89 90 void InitStack(Stack *S) 91 { 92 int i; 93 S->top=0; 94 for(i=0;i<=MAX;i++) 95 S->stack[S->top]=NULL; 96 } 97 98 int InitQueue(Queue *Q) 99 { 100 Q->head=/*(Queue *)*/malloc(sizeof(Queue)); 101 if(Q->head!=NULL) 102 { 103 Q->head->next=NULL; 104 Q->rear=Q->head; 105 return(1); 106 } 107 else return(-1); 108 } 109 110 void PRINT(Elemtype *e) 111 { 112 printf(" "); 113 printf("************************************************** "); 114 printf("* car is leave,the car num is * "); 115 printf("* %s * ",e->num); 116 printf("************************************************** "); 117 } 118 119 int Arrival(Stack *S,Queue *Q) 120 { 121 Elemtype *e; 122 Line_car *q; 123 e=(Elemtype*)malloc(sizeof(Elemtype)); 124 /*flushall();*/ 125 printf("************************************************** "); 126 printf("* please enter car number like :BMW99: * "); 127 printf(" "); 128 scanf("%s",e->num); 129 printf("************************************************** "); 130 if(S->top<MAX) /*车场未满,车进车场*/ 131 { 132 S->top++; 133 printf("************************************************** "); 134 printf("* car is parking in no.%d lacation * ",S->top); 135 printf("************************************************** "); 136 S->stack[S->top]=e; 137 return(1); 138 } 139 else /*车场已满,车进便道*/ 140 { printf("************************************************** "); 141 printf("* park is in full,car in wating line * "); 142 printf("************************************************** "); 143 q=(Line_car*)malloc(sizeof(Line_car)); 144 q->ptr_car=e; 145 q->next=NULL; 146 Q->rear->next=q; 147 Q->rear=q; 148 return(1); 149 } 150 } 151 152 int Leave(Stack S,Stack Ts,Queue Q)/*车辆离开*/ 153 { 154 int i; 155 /*判断车场内是否有车*/ 156 157 while(1) 158 { 159 printf("************************************************** "); 160 printf("* leave car in park or in first line * "); 161 printf("* enter 1 to leave car in park * "); 162 printf("* enter 2 to leave car in first line * "); 163 printf("* enter 3 to exit leave car * "); 164 printf("************************************************** "); 165 while(1) 166 { 167 scanf("%d",&i); 168 if(i<1||i>3) 169 { 170 printf("************************************************** "); 171 printf("* error number enter again * "); 172 printf("************************************************** "); 173 break; 174 } 175 switch(i) 176 { 177 case 1 :Leavepark(&S,&Ts,&Q);break; 178 case 2 :Leaveline(&Q);break; 179 case 3 :return 0; 180 default : break; 181 } 182 printf("************************************************** "); 183 printf("* leave car in park or in first line * "); 184 printf("* enter 1 to leave car in park * "); 185 printf("* enter 2 to leave car in first line * "); 186 printf("* enter 3 to exit leave car * "); 187 printf("************************************************** "); 188 } 189 } 190 return 0; 191 } 192 193 void Leavepark(Stack *S,Stack *Ts,Queue *Q) 194 { 195 196 int park_where; 197 Elemtype *parking,*temp_parking; 198 Line_car *q; 199 if(S->top>0) /*有车*/ 200 { 201 while(1) /*输入离开车辆的信息*/ 202 { 203 Listpark(S); 204 printf("************************************************** "); 205 printf("* parking car number is %d * ",S->top); 206 printf("* please choose a parking number to leave * "); 207 printf(" "); 208 scanf("%d",&park_where); 209 printf("************************************************** "); 210 if(park_where>=1&&park_where<=S->top) break; 211 } 212 while(S->top>park_where) /*车辆离开*/ 213 { 214 Ts->top++; 215 Ts->stack[Ts->top]=S->stack[S->top]; 216 S->stack[S->top]=NULL; 217 S->top--; 218 } 219 parking=S->stack[S->top]; 220 S->stack[S->top]=NULL; 221 S->top--; 222 while(S->top>=1) 223 { 224 S->top++; 225 S->stack[S->top]=Ts->stack[Ts->top]; 226 Ts->stack[Ts->top]=NULL; 227 Ts->top--; 228 } 229 PRINT(parking); 230 /*判断通道上是否有车及车站是否已满*/ 231 if((Q->head!=Q->rear)&&S->top<MAX) /*便道的车辆进入车场*/ 232 { 233 q=Q->head->next; 234 temp_parking=q->ptr_car; 235 S->top++; 236 printf("************************************************** "); 237 printf(" car number:%s ",temp_parking->num); 238 printf("* car is leaving line * "); 239 printf("* car is in parking No. %d location * ",S->top); 240 printf("* car is parking successful * "); 241 printf("************************************************** "); 242 Q->head->next=q->next; 243 if(q==Q->rear) Q->rear=Q->head; 244 S->stack[S->top]=temp_parking; 245 free(q); 246 } 247 else 248 { 249 printf("************************************************** "); 250 printf("* there is no car in the line * "); 251 printf("************************************************** "); 252 } 253 } 254 else 255 { 256 printf("************************************************** "); 257 printf("* there is no car in the park * "); 258 printf("************************************************** "); 259 } /*没车*/ 260 } 261 262 void Leaveline(Queue *Q) 263 { 264 Line_car *q; 265 Elemtype *line_parking; 266 if(Q->head!=Q->rear) 267 { 268 q=Q->head->next; 269 line_parking=q->ptr_car; 270 printf("************************************************** "); 271 printf("* car number is %s * ",line_parking->num); 272 printf("* car is leaving line * "); 273 printf("* car leave line successful * "); 274 printf("************************************************** "); 275 Q->head->next=q->next; 276 if(q==Q->rear) Q->rear=Q->head; 277 free(q); 278 } 279 else 280 { 281 printf("************************************************** "); 282 printf("* there is no car in the line * "); 283 printf("************************************************** "); 284 } 285 } 286 287 void Listpark(Stack *S) /*列表显示车场信息*/ 288 { 289 int i; 290 if(S->top>0) /*判断车站内是否有车*/ 291 { 292 printf("************************************************** "); 293 printf("* parking listing: * "); 294 printf("************************************************** "); 295 for(i=1;i<=S->top;i++) 296 { 297 printf("************************************************** "); 298 printf(" location No.%d ",i); 299 printf(" car number is %s ",S->stack[i]->num); 300 printf("************************************************** "); 301 } 302 } 303 else 304 { 305 printf("************************************************** "); 306 printf("* there is no car in the park * "); 307 printf("************************************************** "); 308 } 309 } 310 311 void Listline(Queue *Q) /*列表显示便道信息*/ 312 { 313 Line_car *p; 314 p=Q->head->next; 315 if(Q->head!=Q->rear) /*判断通道上是否有车*/ 316 { 317 printf("************************************************** "); 318 printf("* line listing: * "); 319 printf("************************************************** "); 320 while(p!=NULL) 321 { 322 printf("************************************************** "); 323 printf(" car number is %s ",p->ptr_car->num); 324 printf("************************************************** "); 325 p=p->next; 326 } 327 } 328 else 329 { 330 printf("************************************************** "); 331 printf("* there is no car in the line * "); 332 printf("************************************************** "); 333 } 334 } 335 336 337 void List(Stack S,Queue W) 338 { 339 int flag,tag; 340 flag=1; 341 while(flag) 342 { 343 printf("************************************************** "); 344 printf("* please select: * "); 345 printf("* enter 1 to look all parking car * "); 346 printf("* enter 2 to look all line car * "); 347 printf("* enter 3 to exit look list system * "); 348 printf("************************************************** "); 349 while(1) 350 { 351 scanf("%d",&tag); 352 if(tag>=1||tag<=3) break; 353 else 354 { 355 printf("************************************************** "); 356 printf("* please select: * "); 357 printf("* enter 1 to look all parking car * "); 358 printf("* enter 2 to look all line car * "); 359 printf("* enter 3 to exit look list system * "); 360 printf("************************************************** "); 361 } 362 } 363 switch(tag) 364 { 365 case 1:Listpark(&S);break; /*列表显示车场信息*/ 366 case 2:Listline(&W);break; /*列表显示便道信息*/ 367 case 3:flag=0;break; 368 default: break; 369 } 370 } 371 }