【C和C++】停车场系统
功能:
默认了最大车位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\n"); 11 printf("you can enter any key to continue\n"); 12 getchar(); 13 system("cls"); 14 } 15 16 /////////////////////////////////////////////////////////////////////////////// 17 18 /////////////////////////////////////////////////////////////////////////////// 19 void display_menu() 20 { 21 printf("**************************************************\n"); 22 printf("* welcome to parking system *\n"); 23 printf("* menu: *\n"); 24 printf("* enter 1 to creat a car to parking *\n"); 25 printf("* enter 2 to leave a car from system *\n"); 26 printf("* enter 3 to listing all car position *\n"); 27 printf("* enter 4 to exit system *\n"); 28 printf("**************************************************\n"); 29 } 30 31 //////////////////////////////////////////////////////////////////////////// 32 33 ///////////////////////////////////////////////////////////////////////////// 34 void display_arrive_menu(Elemtype *e) 35 { 36 printf("**************************************************\n"); 37 printf("* please enter car number like :BMW99: *\n"); 38 printf("\t\t"); 39 scanf("%s",e->num); 40 printf("**************************************************\n\n"); 41 } 42 43 //////////////////////////////////////////////////////////////////////////////// 44 45 //////////////////////////////////////////////////////////////////////////////// 46 47 void display_arrive_unfull(int count) 48 { 49 printf("**************************************************\n"); 50 printf("* car is parking in NO.%d lacation *\n",count); 51 printf("**************************************************\n\n"); 52 } 53 54 //////////////////////////////////////////////////////////////////////////// 55 56 /////////////////////////////////////////////////////////////////////////// 57 58 void display_arrive_full() 59 { 60 printf("**************************************************\n"); 61 printf("* park is in full,car in wating line *\n"); 62 printf("**************************************************\n\n"); 63 } 64 65 ////////////////////////////////////////////////////////////////////////////// 66 67 ////////////////////////////////////////////////////////////////////////////// 68 69 void display_leave_menu() 70 { 71 printf("**************************************************\n"); 72 printf("* leave car in park or in first line *\n"); 73 printf("* enter 1 to leave car in park *\n"); 74 printf("* enter 2 to leave car in first line *\n"); 75 printf("* enter 3 to exit leave car *\n"); 76 printf("**************************************************\n\n"); 77 } 78 79 ///////////////////////////////////////////////////////////////////////////// 80 81 ////////////////////////////////////////////////////////////////////////////// 82 83 void display_error_number() 84 { 85 printf("**************************************************\n"); 86 printf("* error number enter again *\n"); 87 printf("**************************************************\n\n"); 88 } 89 90 ////////////////////////////////////////////////////////////////////////////// 91 92 ////////////////////////////////////////////////////////////////////////////// 93 94 void display_uncar_line() 95 { 96 printf("**************************************************\n"); 97 printf("* there is no car in the line *\n"); 98 printf("**************************************************\n\n"); 99 } 100 101 ////////////////////////////////////////////////////////////////////////////// 102 103 ////////////////////////////////////////////////////////////////////////////// 104 105 void display_uncar_park() 106 { 107 printf("**************************************************\n"); 108 printf("* there is no car in the park *\n"); 109 printf("**************************************************\n\n"); 110 } 111 112 ////////////////////////////////////////////////////////////////////////////// 113 114 ////////////////////////////////////////////////////////////////////////////// 115 116 void display_list_menu() 117 { 118 printf("**************************************************\n"); 119 printf("* please select: *\n"); 120 printf("* enter 1 to look all parking car *\n"); 121 printf("* enter 2 to look all line car *\n"); 122 printf("* enter 3 to exit look list system *\n"); 123 printf("**************************************************\n\n"); 124 } 125 126 ////////////////////////////////////////////////////////////////////////////// 127 128 ////////////////////////////////////////////////////////////////////////////// 129 130 void display_park_menu() 131 { 132 printf("**************************************************\n"); 133 printf("* parking listing: *\n"); 134 printf("**************************************************\n\n"); 135 } 136 137 ////////////////////////////////////////////////////////////////////////////// 138 139 ////////////////////////////////////////////////////////////////////////////// 140 141 void display_line_menu() 142 { 143 printf("**************************************************\n"); 144 printf("* line listing: *\n"); 145 printf("**************************************************\n\n"); 146 } 147 148 ////////////////////////////////////////////////////////////////////////////// 149 150 ////////////////////////////////////////////////////////////////////////////// 151 152 void display_leave_car_info(Elemtype *e) 153 { 154 printf("\n"); 155 printf("**************************************************\n"); 156 printf("* car is leave,the car num is *\n"); 157 printf("* %s *\n",e->num); 158 printf("**************************************************\n\n"); 159 } 160 ////////////////////////////////////////////////////////////////////////////// 161 162 ////////////////////////////////////////////////////////////////////////////// 163 void display_leave_park_menu(int count) 164 { 165 printf("**************************************************\n"); 166 printf("* parking car number is %d *\n",count); 167 printf("* please choose a parking number to leave *\n"); 168 printf("**************************************************\n\n"); 169 } 170 171 ////////////////////////////////////////////////////////////////////////////// 172 173 ////////////////////////////////////////////////////////////////////////////// 174 175 void display_leave_line_to_park(int count,Elemtype *temp_parking) 176 { 177 printf("**************************************************\n"); 178 printf(" car number:%s \n",temp_parking->num); 179 printf("* car is leaving line *\n"); 180 printf("* car is in parking No. %d location *\n",count); 181 printf("**************************************************\n\n"); 182 } 183 184 ////////////////////////////////////////////////////////////////////////////// 185 186 ////////////////////////////////////////////////////////////////////////////// 187 188 void display_leave_line_menu(Elemtype *line_parking) 189 { 190 printf("**************************************************\n"); 191 printf(" car number is %s \n",line_parking->num); 192 printf("* car is leaving line *\n"); 193 printf("* car leave line successful *\n"); 194 printf("**************************************************\n\n"); 195 } 196 197 ////////////////////////////////////////////////////////////////////////////// 198 199 ////////////////////////////////////////////////////////////////////////////// 200 201 void display_list_park(char ch[],int i) 202 { 203 printf("**************************************************\n"); 204 printf(" location No.%d\n",i); 205 printf(" car number is %s\n",ch); 206 printf("**************************************************\n\n"); 207 } 208 209 ////////////////////////////////////////////////////////////////////////////// 210 211 ////////////////////////////////////////////////////////////////////////////// 212 213 void display_list_line(char ch[]) 214 { 215 printf("**************************************************\n"); 216 printf(" car number is %s\n",ch); 217 printf("**************************************************\n\n"); 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("\t\t"); 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("\t\t"); 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\n"); 49 printf("you can enter any key to continue\n"); 50 getch(); 51 system("cls"); 52 while(1) 53 { 54 printf("**************************************************\n"); 55 printf("* welcome to parking system *\n"); 56 printf("* menu: *\n"); 57 printf("* enter 1 to creat a car to parking *\n"); 58 printf("* enter 2 to leave a car from system *\n"); 59 printf("* enter 3 to listing all car position *\n"); 60 printf("* enter 4 to exit system *\n"); 61 printf("**************************************************\n"); 62 while(1) 63 { 64 scanf("%d",&select); 65 if(select<1||select>4) 66 { 67 printf("error number enter again\n");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("**************************************************\n"); 78 printf("* welcome to parking system *\n"); 79 printf("* menu: *\n"); 80 printf("* enter 1 to creat a car to parking *\n"); 81 printf("* enter 2 to leave a car from system *\n"); 82 printf("* enter 3 to listing all car position *\n"); 83 printf("* enter 4 to exit system *\n"); 84 printf("**************************************************\n"); 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("\n"); 113 printf("**************************************************\n"); 114 printf("* car is leave,the car num is *\n"); 115 printf("* %s *\n",e->num); 116 printf("**************************************************\n"); 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("**************************************************\n"); 126 printf("* please enter car number like :BMW99: *\n"); 127 printf("\t\t"); 128 scanf("%s",e->num); 129 printf("**************************************************\n"); 130 if(S->top<MAX) /*车场未满,车进车场*/ 131 { 132 S->top++; 133 printf("**************************************************\n"); 134 printf("* car is parking in no.%d lacation *\n",S->top); 135 printf("**************************************************\n"); 136 S->stack[S->top]=e; 137 return(1); 138 } 139 else /*车场已满,车进便道*/ 140 { printf("**************************************************\n"); 141 printf("* park is in full,car in wating line *\n"); 142 printf("**************************************************\n"); 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("**************************************************\n"); 160 printf("* leave car in park or in first line *\n"); 161 printf("* enter 1 to leave car in park *\n"); 162 printf("* enter 2 to leave car in first line *\n"); 163 printf("* enter 3 to exit leave car *\n"); 164 printf("**************************************************\n"); 165 while(1) 166 { 167 scanf("%d",&i); 168 if(i<1||i>3) 169 { 170 printf("**************************************************\n"); 171 printf("* error number enter again *\n"); 172 printf("**************************************************\n"); 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("**************************************************\n"); 183 printf("* leave car in park or in first line *\n"); 184 printf("* enter 1 to leave car in park *\n"); 185 printf("* enter 2 to leave car in first line *\n"); 186 printf("* enter 3 to exit leave car *\n"); 187 printf("**************************************************\n"); 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("**************************************************\n"); 205 printf("* parking car number is %d *\n",S->top); 206 printf("* please choose a parking number to leave *\n"); 207 printf("\t\t"); 208 scanf("%d",&park_where); 209 printf("**************************************************\n"); 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("**************************************************\n"); 237 printf(" car number:%s \n",temp_parking->num); 238 printf("* car is leaving line *\n"); 239 printf("* car is in parking No. %d location *\n",S->top); 240 printf("* car is parking successful *\n"); 241 printf("**************************************************\n"); 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("**************************************************\n"); 250 printf("* there is no car in the line *\n"); 251 printf("**************************************************\n"); 252 } 253 } 254 else 255 { 256 printf("**************************************************\n"); 257 printf("* there is no car in the park *\n"); 258 printf("**************************************************\n"); 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("**************************************************\n"); 271 printf("* car number is %s *\n",line_parking->num); 272 printf("* car is leaving line *\n"); 273 printf("* car leave line successful *\n"); 274 printf("**************************************************\n"); 275 Q->head->next=q->next; 276 if(q==Q->rear) Q->rear=Q->head; 277 free(q); 278 } 279 else 280 { 281 printf("**************************************************\n"); 282 printf("* there is no car in the line *\n"); 283 printf("**************************************************\n"); 284 } 285 } 286 287 void Listpark(Stack *S) /*列表显示车场信息*/ 288 { 289 int i; 290 if(S->top>0) /*判断车站内是否有车*/ 291 { 292 printf("**************************************************\n"); 293 printf("* parking listing: *\n"); 294 printf("**************************************************\n"); 295 for(i=1;i<=S->top;i++) 296 { 297 printf("**************************************************\n"); 298 printf(" location No.%d\n",i); 299 printf(" car number is %s\n",S->stack[i]->num); 300 printf("**************************************************\n"); 301 } 302 } 303 else 304 { 305 printf("**************************************************\n"); 306 printf("* there is no car in the park *\n"); 307 printf("**************************************************\n"); 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("**************************************************\n"); 318 printf("* line listing: *\n"); 319 printf("**************************************************\n"); 320 while(p!=NULL) 321 { 322 printf("**************************************************\n"); 323 printf(" car number is %s\n",p->ptr_car->num); 324 printf("**************************************************\n"); 325 p=p->next; 326 } 327 } 328 else 329 { 330 printf("**************************************************\n"); 331 printf("* there is no car in the line *\n"); 332 printf("**************************************************\n"); 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("**************************************************\n"); 344 printf("* please select: *\n"); 345 printf("* enter 1 to look all parking car *\n"); 346 printf("* enter 2 to look all line car *\n"); 347 printf("* enter 3 to exit look list system *\n"); 348 printf("**************************************************\n"); 349 while(1) 350 { 351 scanf("%d",&tag); 352 if(tag>=1||tag<=3) break; 353 else 354 { 355 printf("**************************************************\n"); 356 printf("* please select: *\n"); 357 printf("* enter 1 to look all parking car *\n"); 358 printf("* enter 2 to look all line car *\n"); 359 printf("* enter 3 to exit look list system *\n"); 360 printf("**************************************************\n"); 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 }