C語(yǔ)言實(shí)現(xiàn)停車(chē)場(chǎng)項(xiàng)目
本文實(shí)例為大家分享了C語(yǔ)言實(shí)現(xiàn)停車(chē)場(chǎng)項(xiàng)目的具體代碼,供大家參考,具體內(nèi)容如下
停車(chē)場(chǎng)項(xiàng)目需求
問(wèn)題描述:停車(chē)場(chǎng)是一個(gè)能放 n 輛車(chē)的狹長(zhǎng)通道,只有一個(gè)大門(mén),汽車(chē)按到達(dá)的先后次序停放。若車(chē)場(chǎng)滿(mǎn)了,車(chē)要停在門(mén)外的便道上等候,一旦有車(chē)走,則便道上第一輛車(chē)進(jìn)入。當(dāng)停車(chē)場(chǎng)中的車(chē)離開(kāi)時(shí),由于通道窄,在它后面的車(chē)要先退出,待它走后在依次進(jìn)入。汽車(chē)離開(kāi)時(shí)按停放時(shí)間收費(fèi)。
基本功能要求:
(1)建立三個(gè)數(shù)據(jù)結(jié)構(gòu)分別是:停放棧、讓路棧、等候隊(duì)列。
(2)輸入數(shù)據(jù)模擬管理過(guò)程,數(shù)據(jù)(入或出,車(chē)號(hào))
功能描述:進(jìn)車(chē)登記、出車(chē)登記、按車(chē)牌號(hào)查詢(xún)停車(chē)車(chē)輛信息、查詢(xún)出入車(chē)記錄、查詢(xún)場(chǎng)內(nèi)車(chē)輛信息、查詢(xún)等候車(chē)輛信息、退出系統(tǒng)。
(1)linux系統(tǒng)編寫(xiě)(鏈表、棧、隊(duì)列);
(2)進(jìn)車(chē)登記:登記車(chē)牌號(hào)以及入場(chǎng)時(shí)間;
(3)出車(chē)登記:計(jì)算出停車(chē)時(shí)間,記錄車(chē)輛車(chē)牌;
(4)按車(chē)牌號(hào)查詢(xún)車(chē)輛信息:停車(chē)時(shí)間,是否來(lái)過(guò)停車(chē)場(chǎng),是否還在停車(chē)場(chǎng)
(5)查詢(xún)出入記錄:所有車(chē)輛,包括已經(jīng)離開(kāi)的
(6)查詢(xún)場(chǎng)內(nèi)車(chē)輛信息:列出所有場(chǎng)內(nèi)車(chē)輛信息
(7)查詢(xún)等候車(chē)輛信息:顯示等候車(chē)輛數(shù)量以及所有車(chē)牌號(hào)
(8)退出系統(tǒng)。
分析,底層需要寫(xiě)以下內(nèi)容:
兩個(gè)棧,停放棧(車(chē)牌號(hào),出場(chǎng)時(shí)間,入場(chǎng)時(shí)間)[初始化,判斷是否為空,出棧,入棧,查棧] 讓路棧(車(chē)牌號(hào))[初始化,出棧,入棧,判斷是否為空]
一個(gè)隊(duì)列,[初始化,出隊(duì)列,入隊(duì)列](車(chē)牌號(hào))
一個(gè)鏈表,(車(chē)牌號(hào),出入廠(chǎng)狀態(tài),入場(chǎng)時(shí)間,出場(chǎng)時(shí)間)[初始化,入鏈表,查找數(shù)據(jù),遍歷打印]
Windows下代碼
工程分為三個(gè)文件,分別是main.c fun.c pack.h
main.c:
#include<stdio.h> #include"park.h" #include<stdlib.h> #include<time.h> #include<string.h> /* main函數(shù) 功能:顯示界面,判斷用戶(hù)要使用哪個(gè)功能。 入?yún)ⅲ簾o(wú) 返回值:無(wú) */ void main()? { ? ? int ret=0; ? ? char number[10]; ? ? park_init(); ? ? //所有數(shù)據(jù)結(jié)構(gòu)初始化 ? ? //存放用戶(hù)輸入的字符 ? ? while(1)? ? ? { ? ? ? ? /*顯示界面*/ ? ? ? ? printf("################## ? ? ? ? ?停車(chē)場(chǎng) ?v1.0 ? ? ? ? ? ##################\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("#####################################################################\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 1-----------------進(jìn)車(chē)登記------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 2-----------------出車(chē)登記------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 3-----------------車(chē)輛查詢(xún)------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 4-----------------出入記錄------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 5-----------------場(chǎng)內(nèi)車(chē)輛------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 6-----------------等候車(chē)輛------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 7-----------------退出系統(tǒng)------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("#####################################################################\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?201808 ? ? ? ? ? #\n"); ? ? ? ? printf("#####################################################################\n"); ? ? ? ? gets( number ); ? ? ? ? switch ( *number ) //選擇需要什么功能? ? ? ? ? { ? ? ? ? ? ? case '1': //進(jìn)車(chē)登記? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? ? ? ret=car_in(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? printf("入車(chē)成功!\n"); ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '2': //出車(chē)登記? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? ? ? ret=car_out(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? printf("出車(chē)成功!\n"); ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '3': //查找車(chē)輛? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? ? ? ret=find_car(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? //printf("-------------------------------------------------------------------------------------------------------------"); ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '4': //出入記錄? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? ? ? ret=record_all(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '5': //場(chǎng)內(nèi)車(chē)輛? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? ? ? ret=car_park(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '6':? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? ? ? //等候車(chē)輛 ? ? ? ? ? ? ? ? ret=Car_wait(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '7': ? ? ? ? ? ? ? ? ? ? ? ? printf("歡迎下次使用\n"); ? ? ? ? ? ? break; ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? printf( "操作錯(cuò)誤,此項(xiàng)不存在!\n" ); ? ? ? ? ? ? getchar(); ? ? ? ? ? ? system("cls"); ? ? ? ? ? ? break; ? ? ? ? } ? ? ? ? if ( strcmp( number, "7" ) == 0 ) ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? } }
park.h
#ifndef _PARK_H #define _PAEK_H #include <time.h> #include <stdio.h> #define SUCCESS 10000 #define FAILURE 10001 #define TRUE 10002 #define FALSE 10003 #define SIZE 6 ? //車(chē)場(chǎng)大小 /*汽車(chē)信息,節(jié)點(diǎn)結(jié)構(gòu)體 */ struct car_info? { ? ? char name[10]; ? ? // ?車(chē)牌 ? ? time_t time1; ? ? // ?入場(chǎng)時(shí)間 ? ? time_t time2; ? ? // ?出場(chǎng)時(shí)間 } ; typedef struct car_info CAR_I; /*停放,讓路順序棧結(jié)構(gòu)體 需要的參數(shù)為 :車(chē)牌號(hào),出場(chǎng)時(shí)間,入場(chǎng)時(shí)間 配套的子函數(shù) :初始化,判斷是否為空,出棧,入棧,查棧*/ struct sequencestack? { ? ? int top; ? ? CAR_I *date; } ; typedef struct sequencestack ST; /*隊(duì)列節(jié)點(diǎn)結(jié)構(gòu)體 需要的參數(shù)為 :車(chē)牌號(hào),下一個(gè)節(jié)點(diǎn)地址 */ struct car_wait? { ? ? char name[10]; ? ? struct car_wait *next; } ; typedef struct car_wait CAR_W; /*等候鏈?zhǔn)疥?duì)列結(jié)構(gòu) 需要的參數(shù)為 :頭指針,尾指針 配套的子函數(shù) :初始化,出隊(duì)列,入隊(duì)列 */ struct linkqueue? { ? ? CAR_W *front; ? ? CAR_W *rear; } ; typedef struct linkqueue LQ; /*存放所有信息的鏈表 需要的參數(shù)為:車(chē)牌號(hào),出入廠(chǎng)狀態(tài),入場(chǎng)時(shí)間,出場(chǎng)時(shí)間,下一個(gè)節(jié)點(diǎn)的地址 需要的函數(shù)為:初始化,入鏈表,查找數(shù)據(jù),遍歷打印 */ struct all_info? { ? ? char name[10]; ? ? char sit[10]; ? ? time_t time1; ? ? // ?入場(chǎng)時(shí)間 ? ? time_t time2; ? ? // ?出場(chǎng)時(shí)間 ? ? struct all_info *next; } ; typedef struct all_info A_INFO; int car_in(); int car_out(); int find_car(); int record_all(); int car_park(); int Car_wait(); int STinit(ST **q); int STempty(ST *q); int STinsert(ST *q, char na[] ,time_t time); int STout(ST *q,char *a, time_t *time); int LQinit(LQ **q); int LQinsert(LQ *q, char na[]); int LQout(LQ *q, char *a); int LLinit(A_INFO **q); int LLinsert(A_INFO *q, int n, char na[], char s[], time_t timeA, time_t timeB); int LLfind(A_INFO *q, char na[]); int LLget(A_INFO *q, int n, A_INFO **k); int LLtra(A_INFO *q); int parkadd(CAR_I car[], char na[], time_t time); int parkdel(CAR_I car[] ,char na[],time_t time); int print(CAR_I car[]); int park_init(); struct tm * local_time(time_t *tmpcal_ptr); int exchange(A_INFO *q, char na[], char s[]); #endif
fun.c
#include<stdio.h> #include"park.h" #include<stdlib.h>? #include<time.h> #include<string.h> int num = 0; //場(chǎng)內(nèi)車(chē)輛數(shù) ST *stack_park; //停放棧 ST *stack_exchange; //交換棧 LQ *queue_wait; //等候隊(duì)列 A_INFO ?*all_car; //存放所有信息的鏈表 /* 順序棧初始化: ? ? 參數(shù):結(jié)構(gòu)體指針 */ int STinit(ST **q)? { ? ? if(q == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? *q = (ST *)malloc(sizeof(ST)*1); ? ? //為結(jié)構(gòu)體指針?lè)峙淇臻g ? ? (*q)->top = -1; ? ? (*q)->date = (CAR_I *)malloc(sizeof(CAR_I)*SIZE); ? ? //為內(nèi)容指針?lè)峙淇臻g ? ? return SUCCESS; } /* 順序棧判斷是否為空 ? ? 參數(shù):結(jié)構(gòu)體指針 */ int STempty(ST *q)? { ? ? if(q == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? return(q->top == -1)? TRUE:FALSE; ? ? //空返回true ? 不空返回false } /* 順序棧入棧 ? ? 參數(shù):結(jié)構(gòu)體指針,車(chē)牌,入場(chǎng)時(shí)間 */ int STinsert(ST *q, char na[] ,time_t time)? { ? ? if(q == NULL || q->top >= SIZE-1)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? strcpy( q->date[q->top+1].name, na ); ? ? q->date[q->top+1].time1 = time; ? ? q->top++; ? ? return SUCCESS; } /* 結(jié)構(gòu)體出棧 ? ? 參數(shù):結(jié)構(gòu)體指針,保存車(chē)牌的形參,保存入場(chǎng)時(shí)間的結(jié)構(gòu)體指針 */ int STout(ST *q,char *a, time_t *time)? { ? ? if(q == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? ? ? //錯(cuò)誤返回failure ? ? } ? ? if(q->top == -1)? ? ? { ? ? ? ? return FALSE; ? ? ? ? //空返回false ? ? } ? ? strcpy(a, q->date[q->top].name); ? ? //a被修改為出場(chǎng)的車(chē)牌 ? ? *time = q->date[q->top].time1; ? ? //time被修改為入場(chǎng)時(shí)間 ? ? q->top--; ? ? return SUCCESS; } /* 鏈?zhǔn)疥?duì)列初始化 ? ? 參數(shù):隊(duì)列的結(jié)構(gòu)體指針 */ int LQinit(LQ **q)? { ? ? CAR_W (*p); ? ? (*q) = (LQ *)malloc(sizeof(LQ)); ? ? if( (*q) == NULL )? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = (CAR_W *)malloc(sizeof(CAR_W)); ? ? if(p == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p->next = NULL; ? ? (*q)->front = (*q)->rear =p; ? ? return SUCCESS; } /* 鏈?zhǔn)疥?duì)列入隊(duì) ? ? 參數(shù):隊(duì)列的結(jié)構(gòu)體指針,車(chē)牌 */ int LQinsert(LQ *q, char na[])? { ? ? CAR_W *p; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = (CAR_W *)malloc(sizeof(CAR_W)); ? ? if (NULL == p)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? strcpy(p->name, na); ? ? p->next = NULL; ? ? q->rear->next = p; ? ? q->rear = p; ? ? return SUCCESS; } /* 鏈?zhǔn)疥?duì)列出隊(duì) ? ? 參數(shù):隊(duì)列結(jié)構(gòu)體指針 */ int LQout(LQ *q, char *a)? { ? ? // ?char na[10]; ? ? CAR_W *p = q->front->next; ? ? if (NULL == q )? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? if(q->rear == q->front)? ? ? { ? ? ? ? return FALSE; ? ? } ? ? strcpy(a, p->name); ? ? q->front->next = p->next; ? ? if (NULL == p->next)? ? ? { ? ? ? ? q->rear = q->front; ? ? ? ? //用參數(shù)a保存出去的車(chē)牌 ? ? } ? ? free(p); ? ? return SUCCESS; } /* 鏈表初始化 ? ? 參數(shù):頭指針 */ int LLinit(A_INFO **q)? { ? ? (*q) = (A_INFO *)malloc(sizeof(A_INFO)); ? ? if( (*q) == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? (*q)->next = NULL; ? ? return SUCCESS; } /* ? ?鏈表插入(頭插) ? ? ? ? 參數(shù):頭指針,插入的位置(1), 車(chē)牌, 狀態(tài), 入場(chǎng)時(shí)間, 出場(chǎng)時(shí)間 */ int LLinsert(A_INFO *q, int n, char na[], char s[], time_t timeA, time_t timeB)? { ? ? A_INFO *l; ? ? A_INFO *p = q; ? ? int k = 1; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? while(k < n && p != NULL)? ? ? { ? ? ? ? p=p->next; ? ? ? ? k++; ? ? } ? ? if(k > n || p == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? l = (A_INFO *)malloc(sizeof(A_INFO)*1); ? ? if (NULL == l)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? strcpy(l->name, na); ? ? strcpy(l->sit ,s); ? ? l->time1 = timeA; ? ? l->time2 = timeB; ? ? l->next = p->next; ? ? p->next = l; ? ? return SUCCESS; } /* 鏈表定位 ? ? 參數(shù): 頭指針,車(chē)牌 */ int LLfind(A_INFO *q, char na[])? { ? ? A_INFO *p; ? ? int len; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q->next; ? ? len = 1; ? ? while(p)? ? ? { ? ? ? ? if(strcmp(p->name, na) == 0)? ? ? ? ? { ? ? ? ? ? ? return len; ? ? ? ? ? ? //找到返回位置 ? ? ? ? } ? ? ? ? p = p->next; ? ? ? ? len++; ? ? } ? ? return FALSE; ? ? //未找到返回false } /* 鏈表查詢(xún) ? ? ? ? 參數(shù):頭指針,位置 */ int LLget(A_INFO *q, int n, A_INFO **k)? { ? ? int i; ? ? A_INFO *p = q; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? for (i = 0; i < n && p != NULL ; i++)? ? ? { ? ? ? ? p = p->next; ? ? } ? ? if(!p)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? (*k) = p; ? ? //用k指針保存找到的結(jié)構(gòu)體地址 ? ? return SUCCESS; } /* 鏈表遍歷 ? ? 參數(shù):頭指針 */ int LLtra(A_INFO *q)? { ? ? double cost; ? ? struct tm *time1; ? ? struct tm *time2; ? ? time_t timenow; ? ? A_INFO *p; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q; ? ? while (p->next)? ? ? { ? ? ? ? p = p->next; ? ? ? ? ////////////////////記得改這里 ? ? ? ? time1 = local_time(&p->time1); ? ? ? ? if(time1 != NULL)? ? ? ? ? { ? ? ? ? ? ? printf("車(chē)牌:%s ? 狀態(tài):%s ? 入場(chǎng)時(shí)間:%d:%d:%d",p->name,p->sit, time1->tm_hour, time1->tm_min, time1->tm_sec); ? ? ? ? ? ? time2 = local_time(&p->time2); ? ? ? ? ? ? if(time2 != NULL)? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? cost = difftime(p->time2,p->time1); ? ? ? ? ? ? ? ? printf(" ?出場(chǎng)時(shí)間:%d:%d:%d", time2->tm_hour, time2->tm_min, time2->tm_sec); ? ? ? ? ? ? ? ? printf(" ?停車(chē)時(shí)間:%f秒\n",cost); ? ? ? ? ? ? ? ? printf("-------------------------------------------------------------------------------------------------------------\n"); ? ? ? ? ? ? } else? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? time(&timenow); ? ? ? ? ? ? ? ? cost = difftime(timenow,p->time1); ? ? ? ? ? ? ? ? printf(" ?停車(chē)時(shí)間為:%f秒\n" ,cost); ? ? ? ? ? ? ? ? printf("-------------------------------------------------------------------------------------------------------------\n"); ? ? ? ? ? ? ? ? //return 0; ? ? ? ? ? ? } ? ? ? ? } else? ? ? ? ? { ? ? ? ? ? ? printf("車(chē)牌:%s ?排隊(duì)中\(zhòng)n",p->name); ? ? ? ? ? ? printf("-------------------------------------------------------------------------------------------------------------\n"); ? ? ? ? ? ? // ?return 0; ? ? ? ? } ? ? } ? ? return SUCCESS; } /* 結(jié)構(gòu)體數(shù)組增加 ? ? 參數(shù):結(jié)構(gòu)體數(shù)組, 車(chē)牌,入場(chǎng)時(shí)間(下標(biāo)使用全局變量-車(chē)的數(shù)量) */ int parkadd(CAR_I car[], char na[], time_t time)? { ? ? if(num>=6)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? strcpy(car[num].name, na); ? ? car[num].time1 = time; ? ? num++; ? ? return SUCCESS; } /* 結(jié)構(gòu)體數(shù)組減少 ? ? 參數(shù):同上(時(shí)間為出廠(chǎng)) */ int parkdel(CAR_I car[] ,char na[],time_t time)? { ? ? int i; ? ? if(num == 0)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? for (i = 0; i < num; i++)? ? ? { ? ? ? ? if(strcmp(car[i].name, na)==0)? ? ? ? ? { ? ? ? ? ? ? for (; i<num; i++)? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? car[i] = car[i+1]; ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? } ? ? } ? ? num--; ? ? return SUCCESS; } /* 打印所有 ? ? 參數(shù):結(jié)構(gòu)體數(shù)組 */ int print(CAR_I car[])? { ? ? int i; ? ? for (i = 0; i<num; i++)? ? ? { ? ? ? ? printf("場(chǎng)內(nèi)車(chē)輛信息"); ? ? } ? ? return SUCCESS; } /* 修改鏈表狀態(tài)函數(shù) ? ? 參數(shù) :頭指針,所需修改的車(chē)牌,修改為的狀態(tài) */ int exchange(A_INFO *q, char na[], char s[])? { ? ? A_INFO *p; ? ? int len; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q->next; ? ? len = 1; ? ? while(p)? ? ? { ? ? ? ? if(strcmp(p->name, na) == 0)? ? ? ? ? { ? ? ? ? ? ? strcpy( p->sit, s ) ; ? ? ? ? ? ? return SUCCESS; ? ? ? ? } ? ? ? ? p = p->next; ? ? ? ? len++; ? ? } ? ? return FALSE; } /* 修改鏈表time2函數(shù) ? ? 參數(shù) :頭指針,所需修改的車(chē)牌,修改為的time */ int exchange1(A_INFO *q, char na[], time_t tmpcal_ptr)? { ? ? A_INFO *p; ? ? int len; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q->next; ? ? len = 1; ? ? while(p)? ? ? { ? ? ? ? if(strcmp(p->name, na) == 0)? ? ? ? ? { ? ? ? ? ? ? p->time2 = tmpcal_ptr; ? ? ? ? ? ? return SUCCESS; ? ? ? ? } ? ? ? ? p = p->next; ? ? ? ? len++; ? ? } ? ? return FALSE; } /* 修改鏈表time1函數(shù) ? ? 參數(shù) :頭指針,所需修改的車(chē)牌,修改為的time */ int exchange2(A_INFO *q, char na[], time_t tmpcal_ptr)? { ? ? A_INFO *p; ? ? int len; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q->next; ? ? len = 1; ? ? while(p)? ? ? { ? ? ? ? if(strcmp(p->name, na) == 0)? ? ? ? ? { ? ? ? ? ? ? p->time1 = tmpcal_ptr; ? ? ? ? ? ? return SUCCESS; ? ? ? ? } ? ? ? ? p = p->next; ? ? ? ? len++; ? ? } ? ? return FALSE; } /*//////////////////////////////////// 進(jìn)車(chē)登記函數(shù) 功能:車(chē)輛進(jìn)入登記,修改各存放結(jié)構(gòu)體中的信息。 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int car_in()? { ? ? int i; ? ? char a[12]; ? ? //記錄車(chē)牌號(hào) ? ? int ret; ? ? time_t tmpcal_ptr; ? ? time_t tmpcal_ptr1; ? ? time_t tmpcal_ptr2; ? ? //為了給出車(chē)時(shí)間賦空值 ? ? printf("請(qǐng)輸入車(chē)牌號(hào):\n"); ? ? gets(a); ? ? time(&tmpcal_ptr); ? ? ret=STinsert(stack_park, a ,tmpcal_ptr); ? ? if(ret==FAILURE)? ? ? { ? ? ? ? printf("停車(chē)場(chǎng)已滿(mǎn),排隊(duì)中\(zhòng)n"); ? ? ? ? ret=LQinsert(queue_wait, a); ? ? ? ? LLinsert(all_car, 1, a, "排隊(duì)中",tmpcal_ptr1, tmpcal_ptr2); ? ? ? ? // exchange(all_car, a, "排隊(duì)中"); ? ? ? ? if(FAILURE==ret)? ? ? ? ? { ? ? ? ? ? ? return FAILURE; ? ? ? ? } ? ? } else? ? ? { ? ? ? ? LLinsert(all_car, 1, a, "在場(chǎng)中",tmpcal_ptr, tmpcal_ptr2); ? ? } ? ? for (i=0; i<stack_park->top+1; i++)? ? ? { ? ? ? ? printf("車(chē)牌 :%s\n",stack_park->date[i].name); ? ? } ? ? return SUCCESS; } /*//////////////////////////////////// 出車(chē)登記函數(shù) 功能:車(chē)輛出場(chǎng)登記,修改各存放結(jié)構(gòu)體中的信息。 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int car_out()? { ? ? char a[12]; ? ? char b[12]; ? ? char c[12]; ? ? int ret; ? ? time_t tmpcal_ptr3; ? ? //出場(chǎng)時(shí)間 ? ? time_t tmpcal_ptr4; ? ? // ? ? printf("\n請(qǐng)輸入出車(chē)車(chē)牌號(hào):\n\n"); ? ? gets(a); ? ? time(&tmpcal_ptr3); ? ? // ?ret =STout(stack_park, b, &tmpcal_ptr4 ); ? ? // ?while(strcmp(b,a)!=0) ? ? while((ret = STout(stack_park, b, &tmpcal_ptr4 ))!=FALSE)? ? ? { ? ? ? ? if(strcmp(b,a)==0)? ? ? ? ? { ? ? ? ? ? ? break; ? ? ? ? } ? ? ? ? STinsert(stack_exchange, b, tmpcal_ptr4); ? ? ? ? // ?ret =STout(stack_park, b, &tmpcal_ptr4 ); ? ? } ? ? if(ret == FALSE)? ? ? { ? ? ? ? printf("未找到該車(chē)!\n\n"); ? ? ? ? while( (ret = STout(stack_exchange,b,&tmpcal_ptr4)) != FALSE)? ? ? ? ? { ? ? ? ? ? ? STinsert(stack_park, b,tmpcal_ptr4 ); ? ? ? ? } ? ? ? ? return FAILURE; ? ? } else? ? ? { ? ? ? ? ret = exchange(all_car , b ,"出場(chǎng)了"); ? ? ? ? ret = exchange1(all_car ,b ,tmpcal_ptr3); ? ? ? ? while( (ret = STout(stack_exchange,b,&tmpcal_ptr4)) != FALSE)? ? ? ? ? { ? ? ? ? ? ? STinsert(stack_park, b,tmpcal_ptr4 ); ? ? ? ? } ? ? ? ? if((ret = LQout(queue_wait, c))!=FALSE)? ? ? ? ? { ? ? ? ? ? ? time(&tmpcal_ptr4); ? ? ? ? ? ? STinsert(stack_park, c,tmpcal_ptr4); ? ? ? ? ? ? ret = exchange(all_car , c ,"在場(chǎng)中"); ? ? ? ? ? ? ret = exchange2(all_car ,c ,tmpcal_ptr3); ? ? ? ? } ? ? } ? ? return SUCCESS; } /*//////////////////////////////////// 尋找車(chē)輛函數(shù) 功能:在存放信息的鏈表中尋找車(chē)輛。 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int find_car()? { ? ? int len; ? ? char a[12]; ? ? double cost; ? ? struct tm *time1; ? ? struct tm *time2; ? ? time_t timenow; ? ? A_INFO *k; ? ? int ret; ? ? printf("請(qǐng)輸入你要查詢(xún)的車(chē)牌:\n"); ? ? gets(a); ? ? len = LLfind(all_car, a); ? ? if(len == FALSE)? ? ? { ? ? ? ? printf("未來(lái)過(guò)\n\n"); ? ? ? ? return FAILURE; ? ? } ? ? ret = LLget(all_car, len, &k); ? ? time1 = local_time(&k->time1); ? ? if(time1 != NULL) ? ? { ? ? printf("車(chē)牌:%s\n狀態(tài):%s\n入場(chǎng)時(shí)間:%d:%d:%d\n",k->name,k->sit, time1->tm_hour, time1->tm_min, time1->tm_sec); ? ? time2 = local_time(&k->time2); ? ? if(time2 != NULL)? ? ? { ? ? ? ? cost = difftime(k->time2,k->time1); ? ? ? ? printf("出場(chǎng)時(shí)間:%d:%d:%d\n", time2->tm_hour, time2->tm_min, time2->tm_sec); ? ? ? ? printf("停車(chē)時(shí)間:%f\n秒",cost); ? ? } else? ? ? { ? ? ? ? time(&timenow); ? ? ? ? cost = difftime(timenow,k->time1); ? ? ? ? printf("出場(chǎng)時(shí)間:未出場(chǎng)\n停車(chē)時(shí)間:%f秒\n",cost); ? ? ? ? return 0; ? ? } ? ? } ? ? else ? ? ? ? printf("等候中"); ? ? return SUCCESS; }//////////////////////// 查看出入登記函數(shù) 功能:遍歷打印存放所有信息的鏈表 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int record_all()? { ? ? LLtra(all_car); ? ? return SUCCESS; } /*//////////////////////////////////// 查看停車(chē)場(chǎng)內(nèi)車(chē)輛信息函數(shù) 功能:遍歷打印存放停車(chē)場(chǎng)內(nèi)信息的數(shù)組 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int car_park()? { ? ? int i; ? ? double cost; ? ? struct tm *time1; ? ? time_t timenow; ? ? for (i=0; i<stack_park->top+1; i++)? ? ? { ? ? ? ? time1 = local_time(&stack_park->date[i].time1); ? ? ? ? printf("車(chē)牌:%s ? ? 入場(chǎng)時(shí)間:%d:%d:%d",stack_park->date[i].name, time1->tm_hour, time1->tm_min, time1->tm_sec); ? ? ? ? time(&timenow); ? ? ? ? cost = difftime(timenow,stack_park->date[i].time1); ? ? ? ? printf(" ?未出場(chǎng),停車(chē)時(shí)間為:%f秒\n\n",cost); ? ? ? ? printf("-------------------------------------------------------------------------------------------------------------\n"); ? ? } ? ? return SUCCESS; } /*//////////////////////////////////// 查看等候隊(duì)列內(nèi)車(chē)輛信息函數(shù) 功能:遍歷打印等候隊(duì)列中車(chē)輛 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int Car_wait()? { ? ? CAR_W *p; ? ? p = queue_wait->front; ? ? while(p->next)? ? ? { ? ? ? ? p=p->next; ? ? ? ? printf("車(chē)牌:%s\n\n",p->name); ? ? } ? ? return SUCCESS; } /*//////////////////////////////////// 初始化函數(shù) 功能:初始化 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int park_init()? { ? ? STinit(&stack_park); ? ? STinit(&stack_exchange); ? ? LQinit(&queue_wait); ? ? LLinit(&all_car); ? ? return SUCCESS; } /*//////////////////////////////////// 時(shí)間函數(shù) 功能:轉(zhuǎn)換成當(dāng)?shù)貢r(shí)間 入?yún)ⅲ簍ime_t *tmpcal_ptr(等待轉(zhuǎn)換的時(shí)間) 返回值:time_local(當(dāng)?shù)貢r(shí)間) ////////////////////////////////////*/ struct tm * local_time(time_t *tmpcal_ptr)? { ? ? struct tm *time_local = NULL; ? ? time_local = localtime(tmpcal_ptr); ? ? //轉(zhuǎn)換成當(dāng)?shù)貢r(shí)間 ? ? return time_local; }
現(xiàn)象:
linux下代碼
分為三個(gè)文件
main_u.c fun_u.c park_u.h
main_u.c
#include<stdio.h> #include"park_u.h" #include<stdlib.h> #include<time.h> #include<string.h> /* main函數(shù) 功能:顯示界面,判斷用戶(hù)要使用哪個(gè)功能。 入?yún)ⅲ簾o(wú) 返回值:無(wú) */ void main()? { ? ? int ret=0; ? ? char number[10]; ? ? park_init(); ? ? //所有數(shù)據(jù)結(jié)構(gòu)初始化 ? ? //存放用戶(hù)輸入的字符 ? ? while(1)? ? ? { ? ? ? ? /*顯示界面*/ ? ? ? ? printf("################## ? ? ? ? ?停車(chē)場(chǎng) ?v1.0 ? ? ? ? ? ##################\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("#####################################################################\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 1-----------------進(jìn)車(chē)登記------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 2-----------------出車(chē)登記------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 3-----------------車(chē)輛查詢(xún)------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 4-----------------出入記錄------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 5-----------------場(chǎng)內(nèi)車(chē)輛------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 6-----------------等候車(chē)輛------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? 7-----------------退出系統(tǒng)------------------- ? ? ? ? ? #\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #\n"); ? ? ? ? printf("#####################################################################\n"); ? ? ? ? printf("# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?201808 ? ? ? ? ? #\n"); ? ? ? ? printf("#####################################################################\n"); ? ? ? ? gets( number ); ? ? ? ? switch ( *number ) //選擇需要什么功能? ? ? ? ? { ? ? ? ? ? ? case '1': //進(jìn)車(chē)登記? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? ? ? ret=car_in(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? printf("入車(chē)成功!\n"); ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '2': //出車(chē)登記? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? ? ? ret=car_out(); ? ? ? ? ? ? ? ? if(ret!=FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("出車(chē)成功!\n"); ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '3': //查找車(chē)輛? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? ? ? ret=find_car(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? //printf("-------------------------------------------------------------------------------------------------------------"); ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '4': //出入記錄? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? ? ? ret=record_all(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '5': //場(chǎng)內(nèi)車(chē)輛? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? ? ? ret=car_park(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '6':? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? ? ? //等候車(chē)輛 ? ? ? ? ? ? ? ? ret=Car_wait(); ? ? ? ? ? ? ? ? if(ret==FAILURE)? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? printf("輸入錯(cuò)誤!\n"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? ? ? case '7': ? ? ? ? ? ? ? ? ? ? ? ? printf("歡迎下次使用\n"); ? ? ? ? ? ? break; ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? printf( "操作錯(cuò)誤,此項(xiàng)不存在!\n" ); ? ? ? ? ? ? getchar(); ? ? ? ? ? ? printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); ? ? ? ? ? ? break; ? ? ? ? } ? ? ? ? if ( strcmp( number, "7" ) == 0 ) ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? } }
fun_u.c
#include<stdio.h> #include"park_u.h" #include<stdlib.h>? #include<time.h> #include<string.h> int num = 0; //場(chǎng)內(nèi)車(chē)輛數(shù) ST *stack_park; //停放棧 ST *stack_exchange; //交換棧 LQ *queue_wait; //等候隊(duì)列 A_INFO ?*all_car; //存放所有信息的鏈表 /* 順序棧初始化: ? ? 參數(shù):結(jié)構(gòu)體指針 */ int STinit(ST **q)? { ? ? if(q == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? *q = (ST *)malloc(sizeof(ST)*1); ? ? //為結(jié)構(gòu)體指針?lè)峙淇臻g ? ? (*q)->top = -1; ? ? (*q)->date = (CAR_I *)malloc(sizeof(CAR_I)*SIZE); ? ? //為內(nèi)容指針?lè)峙淇臻g ? ? return SUCCESS; } /* 順序棧判斷是否為空 ? ? 參數(shù):結(jié)構(gòu)體指針 */ int STempty(ST *q)? { ? ? if(q == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? return(q->top == -1)? TRUE:FALSE; ? ? //空返回true ? 不空返回false } /* 順序棧入棧 ? ? 參數(shù):結(jié)構(gòu)體指針,車(chē)牌,入場(chǎng)時(shí)間 */ int STinsert(ST *q, char na[] ,time_t time)? { ? ? if(q == NULL || q->top >= SIZE-1)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? strcpy( q->date[q->top+1].name, na ); ? ? q->date[q->top+1].time1 = time; ? ? q->top++; ? ? return SUCCESS; } /* 結(jié)構(gòu)體出棧 ? ? 參數(shù):結(jié)構(gòu)體指針,保存車(chē)牌的形參,保存入場(chǎng)時(shí)間的結(jié)構(gòu)體指針 */ int STout(ST *q,char *a, time_t *time)? { ? ? if(q == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? ? ? //錯(cuò)誤返回failure ? ? } ? ? if(q->top == -1)? ? ? { ? ? ? ? return FALSE; ? ? ? ? //空返回false ? ? } ? ? strcpy(a, q->date[q->top].name); ? ? //a被修改為出場(chǎng)的車(chē)牌 ? ? *time = q->date[q->top].time1; ? ? //time被修改為入場(chǎng)時(shí)間 ? ? q->top--; ? ? return SUCCESS; } /* 鏈?zhǔn)疥?duì)列初始化 ? ? 參數(shù):隊(duì)列的結(jié)構(gòu)體指針 */ int LQinit(LQ **q)? { ? ? CAR_W (*p); ? ? (*q) = (LQ *)malloc(sizeof(LQ)); ? ? if( (*q) == NULL )? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = (CAR_W *)malloc(sizeof(CAR_W)); ? ? if(p == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p->next = NULL; ? ? (*q)->front = (*q)->rear =p; ? ? return SUCCESS; } /* 鏈?zhǔn)疥?duì)列入隊(duì) ? ? 參數(shù):隊(duì)列的結(jié)構(gòu)體指針,車(chē)牌 */ int LQinsert(LQ *q, char na[])? { ? ? CAR_W *p; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = (CAR_W *)malloc(sizeof(CAR_W)); ? ? if (NULL == p)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? strcpy(p->name, na); ? ? p->next = NULL; ? ? q->rear->next = p; ? ? q->rear = p; ? ? return SUCCESS; } /* 鏈?zhǔn)疥?duì)列出隊(duì) ? ? 參數(shù):隊(duì)列結(jié)構(gòu)體指針 */ int LQout(LQ *q, char *a)? { ? ? // ?char na[10]; ? ? CAR_W *p = q->front->next; ? ? if (NULL == q )? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? if(q->rear == q->front)? ? ? { ? ? ? ? return FALSE; ? ? } ? ? strcpy(a, p->name); ? ? q->front->next = p->next; ? ? if (NULL == p->next)? ? ? { ? ? ? ? q->rear = q->front; ? ? ? ? //用參數(shù)a保存出去的車(chē)牌 ? ? } ? ? free(p); ? ? return SUCCESS; } /* 鏈表初始化 ? ? 參數(shù):頭指針 */ int LLinit(A_INFO **q)? { ? ? (*q) = (A_INFO *)malloc(sizeof(A_INFO)); ? ? if( (*q) == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? (*q)->next = NULL; ? ? return SUCCESS; } /* ? ?鏈表插入(頭插) ? ? ? ? 參數(shù):頭指針,插入的位置(1), 車(chē)牌, 狀態(tài), 入場(chǎng)時(shí)間, 出場(chǎng)時(shí)間 */ int LLinsert(A_INFO *q, int n, char na[], char s[], time_t timeA, time_t timeB)? { ? ? A_INFO *l; ? ? A_INFO *p = q; ? ? int k = 1; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? while(k < n && p != NULL)? ? ? { ? ? ? ? p=p->next; ? ? ? ? k++; ? ? } ? ? if(k > n || p == NULL)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? l = (A_INFO *)malloc(sizeof(A_INFO)*1); ? ? if (NULL == l)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? strcpy(l->name, na); ? ? strcpy(l->sit ,s); ? ? l->time1 = timeA; ? ? l->time2 = timeB; ? ? l->next = p->next; ? ? p->next = l; ? ? return SUCCESS; } /* 鏈表定位 ? ? 參數(shù): 頭指針,車(chē)牌 */ int LLfind(A_INFO *q, char na[])? { ? ? A_INFO *p; ? ? int len; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q->next; ? ? len = 1; ? ? while(p)? ? ? { ? ? ? ? if(strcmp(p->name, na) == 0)? ? ? ? ? { ? ? ? ? ? ? return len; ? ? ? ? ? ? //找到返回位置 ? ? ? ? } ? ? ? ? p = p->next; ? ? ? ? len++; ? ? } ? ? return FALSE; ? ? //未找到返回false } /* 鏈表查詢(xún) ? ? ? ? 參數(shù):頭指針,位置 */ int LLget(A_INFO *q, int n, A_INFO **k)? { ? ? int i; ? ? A_INFO *p = q; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? for (i = 0; i < n && p != NULL ; i++)? ? ? { ? ? ? ? p = p->next; ? ? } ? ? if(!p)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? (*k) = p; ? ? //用k指針保存找到的結(jié)構(gòu)體地址 ? ? return SUCCESS; } /* 鏈表遍歷 ? ? 參數(shù):頭指針 */ int LLtra(A_INFO *q)? { ? ? double cost; ? ? struct tm *time1; ? ? struct tm *time2; ? ? time_t timenow=0; ? ? A_INFO *p; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q; ? ? while (p->next)? ? ? { ? ? ? ? p = p->next; ? ? ? ? time1 = local_time(&p->time1); ? ? ? ? if(time1 != NULL)? ? ? ? ? { ? ? ? ? ? ? printf("車(chē)牌:%s ? 狀態(tài):%s ? 入場(chǎng)時(shí)間:%d:%d:%d",p->name,p->sit, time1->tm_hour, time1->tm_min, time1->tm_sec); ? ? ? ? ? ? time2 = local_time(&p->time2); ? ? ? ? ? ? if(!(time2->tm_hour==8&&time2->tm_min==0&&time2->tm_sec==0))? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? cost = difftime(p->time2,p->time1); ? ? ? ? ? ? ? ? printf(" ?出場(chǎng)時(shí)間:%d:%d:%d", time2->tm_hour, time2->tm_min, time2->tm_sec); ? ? ? ? ? ? ? ? printf(" ?停車(chē)時(shí)間:%f秒\n",cost); ? ? ? ? ? ? ? ? printf("-------------------------------------------------------------------------------------------------------------\n"); ? ? ? ? ? ? } else? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? time(&timenow); ? ? ? ? ? ? ? ? cost = difftime(timenow,p->time1); ? ? ? ? ? ? ? ? printf(" ?停車(chē)時(shí)間為:%f秒\n" ,cost); ? ? ? ? ? ? ? ? printf("-------------------------------------------------------------------------------------------------------------\n"); ? ? ? ? ? ? ? ? //return 0; ? ? ? ? ? ? } ? ? ? ? } else? ? ? ? ? { ? ? ? ? ? ? printf("車(chē)牌:%s ?排隊(duì)中\(zhòng)n",p->name); ? ? ? ? ? ? printf("-------------------------------------------------------------------------------------------------------------\n"); ? ? ? ? ? ? // ?return 0; ? ? ? ? } ? ? } ? ? return SUCCESS; } /* 結(jié)構(gòu)體數(shù)組增加 ? ? 參數(shù):結(jié)構(gòu)體數(shù)組, 車(chē)牌,入場(chǎng)時(shí)間(下標(biāo)使用全局變量-車(chē)的數(shù)量) */ int parkadd(CAR_I car[], char na[], time_t time)? { ? ? if(num>=6)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? strcpy(car[num].name, na); ? ? car[num].time1 = time; ? ? num++; ? ? return SUCCESS; } /* 結(jié)構(gòu)體數(shù)組減少 ? ? 參數(shù):同上(時(shí)間為出廠(chǎng)) */ int parkdel(CAR_I car[] ,char na[],time_t time)? { ? ? int i; ? ? if(num == 0)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? for (i = 0; i < num; i++)? ? ? { ? ? ? ? if(strcmp(car[i].name, na)==0)? ? ? ? ? { ? ? ? ? ? ? for (; i<num; i++)? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? car[i] = car[i+1]; ? ? ? ? ? ? } ? ? ? ? ? ? break; ? ? ? ? } ? ? } ? ? num--; ? ? return SUCCESS; } /* 打印所有 ? ? 參數(shù):結(jié)構(gòu)體數(shù)組 */ int print(CAR_I car[])? { ? ? int i; ? ? for (i = 0; i<num; i++)? ? ? { ? ? ? ? printf("場(chǎng)內(nèi)車(chē)輛信息"); ? ? } ? ? return SUCCESS; } /* 修改鏈表狀態(tài)函數(shù) ? ? 參數(shù) :頭指針,所需修改的車(chē)牌,修改為的狀態(tài) */ int exchange(A_INFO *q, char na[], char s[])? { ? ? A_INFO *p; ? ? int len; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q->next; ? ? len = 1; ? ? while(p)? ? ? { ? ? ? ? if(strcmp(p->name, na) == 0)? ? ? ? ? { ? ? ? ? ? ? strcpy( p->sit, s ) ; ? ? ? ? ? ? return SUCCESS; ? ? ? ? } ? ? ? ? p = p->next; ? ? ? ? len++; ? ? } ? ? return FALSE; } /* 修改鏈表time2函數(shù) ? ? 參數(shù) :頭指針,所需修改的車(chē)牌,修改為的time */ int exchange1(A_INFO *q, char na[], time_t tmpcal_ptr)? { ? ? A_INFO *p; ? ? int len; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q->next; ? ? len = 1; ? ? while(p)? ? ? { ? ? ? ? if(strcmp(p->name, na) == 0)? ? ? ? ? { ? ? ? ? ? ? p->time2 = tmpcal_ptr; ? ? ? ? ? ? return SUCCESS; ? ? ? ? } ? ? ? ? p = p->next; ? ? ? ? len++; ? ? } ? ? return FALSE; } /* 修改鏈表time1函數(shù) ? ? 參數(shù) :頭指針,所需修改的車(chē)牌,修改為的time */ int exchange2(A_INFO *q, char na[], time_t tmpcal_ptr)? { ? ? A_INFO *p; ? ? int len; ? ? if (NULL == q)? ? ? { ? ? ? ? return FAILURE; ? ? } ? ? p = q->next; ? ? len = 1; ? ? while(p)? ? ? { ? ? ? ? if(strcmp(p->name, na) == 0)? ? ? ? ? { ? ? ? ? ? ? p->time1 = tmpcal_ptr; ? ? ? ? ? ? return SUCCESS; ? ? ? ? } ? ? ? ? p = p->next; ? ? ? ? len++; ? ? } ? ? return FALSE; } /*//////////////////////////////////// 進(jìn)車(chē)登記函數(shù) 功能:車(chē)輛進(jìn)入登記,修改各存放結(jié)構(gòu)體中的信息。 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int car_in()? { ? ? int i; ? ? char a[12]; ? ? //記錄車(chē)牌號(hào) ? ? int ret; ? ? time_t tmpcal_ptr; ? ? time_t tmpcal_ptr1; ? ? time_t tmpcal_ptr2; ? ? //為了給出車(chē)時(shí)間賦空值 ? ? printf("請(qǐng)輸入車(chē)牌號(hào):\n"); ? ? gets(a); ? ? time(&tmpcal_ptr); ? ? ret=STinsert(stack_park, a ,tmpcal_ptr); ? ? if(ret==FAILURE)? ? ? { ? ? ? ? printf("停車(chē)場(chǎng)已滿(mǎn),排隊(duì)中\(zhòng)n"); ? ? ? ? ret=LQinsert(queue_wait, a); ? ? ? ? LLinsert(all_car, 1, a, "排隊(duì)中",tmpcal_ptr1, tmpcal_ptr2); ? ? ? ? // exchange(all_car, a, "排隊(duì)中"); ? ? ? ? if(FAILURE==ret)? ? ? ? ? { ? ? ? ? ? ? return FAILURE; ? ? ? ? } ? ? } else? ? ? { ? ? ? ? LLinsert(all_car, 1, a, "在場(chǎng)中",tmpcal_ptr, tmpcal_ptr2); ? ? } ? ? for (i=0; i<stack_park->top+1; i++)? ? ? { ? ? ? ? printf("車(chē)牌 :%s\n",stack_park->date[i].name); ? ? } ? ? return SUCCESS; } /*//////////////////////////////////// 出車(chē)登記函數(shù) 功能:車(chē)輛出場(chǎng)登記,修改各存放結(jié)構(gòu)體中的信息。 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int car_out()? { ? ? char a[12]; ? ? char b[12]; ? ? char c[12]; ? ? int ret; ? ? time_t tmpcal_ptr3; ? ? //出場(chǎng)時(shí)間 ? ? time_t tmpcal_ptr4; ? ? // ? ? printf("\n請(qǐng)輸入出車(chē)車(chē)牌號(hào):\n\n"); ? ? gets(a); ? ? time(&tmpcal_ptr3); ? ? // ?ret =STout(stack_park, b, &tmpcal_ptr4 ); ? ? // ?while(strcmp(b,a)!=0) ? ? while((ret = STout(stack_park, b, &tmpcal_ptr4 ))!=FALSE)? ? ? { ? ? ? ? if(strcmp(b,a)==0)? ? ? ? ? { ? ? ? ? ? ? break; ? ? ? ? } ? ? ? ? STinsert(stack_exchange, b, tmpcal_ptr4); ? ? ? ? // ?ret =STout(stack_park, b, &tmpcal_ptr4 ); ? ? } ? ? if(ret == FALSE)? ? ? { ? ? ? ? printf("未找到該車(chē)!\n\n"); ? ? ? ? while( (ret = STout(stack_exchange,b,&tmpcal_ptr4)) != FALSE)? ? ? ? ? { ? ? ? ? ? ? STinsert(stack_park, b,tmpcal_ptr4 ); ? ? ? ? } ? ? ? ? return FAILURE; ? ? } else? ? ? { ? ? ? ? ret = exchange(all_car , b ,"出場(chǎng)了"); ? ? ? ? ret = exchange1(all_car ,b ,tmpcal_ptr3); ? ? ? ? while( (ret = STout(stack_exchange,b,&tmpcal_ptr4)) != FALSE)? ? ? ? ? { ? ? ? ? ? ? STinsert(stack_park, b,tmpcal_ptr4 ); ? ? ? ? } ? ? ? ? if((ret = LQout(queue_wait, c))!=FALSE)? ? ? ? ? { ? ? ? ? ? ? time(&tmpcal_ptr4); ? ? ? ? ? ? STinsert(stack_park, c,tmpcal_ptr4); ? ? ? ? ? ? ret = exchange(all_car , c ,"在場(chǎng)中"); ? ? ? ? ? ? ret = exchange2(all_car ,c ,tmpcal_ptr3); ? ? ? ? } ? ? } ? ? return SUCCESS; } /*//////////////////////////////////// 尋找車(chē)輛函數(shù) 功能:在存放信息的鏈表中尋找車(chē)輛。 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int find_car()? { ? ? int len; ? ? char a[12]; ? ? double cost; ? ? struct tm *time1; ? ? struct tm *time2; ? ? time_t timenow; ? ? A_INFO *k; ? ? int ret; ? ? printf("請(qǐng)輸入你要查詢(xún)的車(chē)牌:\n"); ? ? gets(a); ? ? len = LLfind(all_car, a); ? ? if(len == FALSE)? ? ? { ? ? ? ? printf("未來(lái)過(guò)\n\n"); ? ? ? ? return FAILURE; ? ? } ? ? ret = LLget(all_car, len, &k); ? ? time1 = local_time(&k->time1); ? ? if(time1 != NULL) ? ? { ? ? printf("車(chē)牌:%s\n狀態(tài):%s\n入場(chǎng)時(shí)間:%d:%d:%d\n",k->name,k->sit, time1->tm_hour, time1->tm_min, time1->tm_sec); ? ? time2 = local_time(&k->time2); ? ? if(time2 != NULL)? ? ? { ? ? ? ? cost = difftime(k->time2,k->time1); ? ? ? ? printf("出場(chǎng)時(shí)間:%d:%d:%d\n", time2->tm_hour, time2->tm_min, time2->tm_sec); ? ? ? ? printf("停車(chē)時(shí)間:%f\n秒",cost); ? ? } else? ? ? { ? ? ? ? time(&timenow); ? ? ? ? cost = difftime(timenow,k->time1); ? ? ? ? printf("出場(chǎng)時(shí)間:未出場(chǎng)\n停車(chē)時(shí)間:%f秒\n",cost); ? ? ? ? return 0; ? ? } ? ? } ? ? else ? ? ? ? printf("等候中"); ? ? return SUCCESS; } /*//////////////////////////////////// 查看出入登記函數(shù) 功能:遍歷打印存放所有信息的鏈表 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int record_all()? { ? ? LLtra(all_car); ? ? return SUCCESS; } /*//////////////////////////////////// 查看停車(chē)場(chǎng)內(nèi)車(chē)輛信息函數(shù) 功能:遍歷打印存放停車(chē)場(chǎng)內(nèi)信息的數(shù)組 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int car_park()? { ? ? int i; ? ? double cost; ? ? struct tm *time1; ? ? time_t timenow; ? ? for (i=0; i<stack_park->top+1; i++)? ? ? { ? ? ? ? time1 = local_time(&stack_park->date[i].time1); ? ? ? ? printf("車(chē)牌:%s ? ? 入場(chǎng)時(shí)間:%d:%d:%d",stack_park->date[i].name, time1->tm_hour, time1->tm_min, time1->tm_sec); ? ? ? ? time(&timenow); ? ? ? ? cost = difftime(timenow,stack_park->date[i].time1); ? ? ? ? printf(" ?未出場(chǎng),停車(chē)時(shí)間為:%f秒\n\n",cost); ? ? ? ? printf("-------------------------------------------------------------------------------------------------------------\n"); ? ? } ? ? return SUCCESS; } /*//////////////////////////////////// 查看等候隊(duì)列內(nèi)車(chē)輛信息函數(shù) 功能:遍歷打印等候隊(duì)列中車(chē)輛 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int Car_wait()? { ? ? CAR_W *p; ? ? p = queue_wait->front; ? ? while(p->next)? ? ? { ? ? ? ? p=p->next; ? ? ? ? printf("車(chē)牌:%s\n\n",p->name); ? ? } ? ? return SUCCESS; } /*//////////////////////////////////// 初始化函數(shù) 功能:初始化 入?yún)ⅲ簾o(wú) 返回值:SUCCESS/FAILURE ////////////////////////////////////*/ int park_init()? { ? ? STinit(&stack_park); ? ? STinit(&stack_exchange); ? ? LQinit(&queue_wait); ? ? LLinit(&all_car); ? ? return SUCCESS; } /*//////////////////////////////////// 時(shí)間函數(shù) 功能:轉(zhuǎn)換成當(dāng)?shù)貢r(shí)間 入?yún)ⅲ簍ime_t *tmpcal_ptr(等待轉(zhuǎn)換的時(shí)間) 返回值:time_local(當(dāng)?shù)貢r(shí)間) ////////////////////////////////////*/ struct tm * local_time(time_t *tmpcal_ptr)? { ? ? struct tm *time_local = NULL; ? ? time_local = localtime(tmpcal_ptr); ? ? //轉(zhuǎn)換成當(dāng)?shù)貢r(shí)間 ? ? return time_local; }
park_u.h
#ifndef _PARK_H #define _PAEK_H #include <time.h> #include <stdio.h> #define SUCCESS 10000 #define FAILURE 10001 #define TRUE 10002 #define FALSE 10003 #define SIZE 6 ? //車(chē)場(chǎng)大小 /*汽車(chē)信息,節(jié)點(diǎn)結(jié)構(gòu)體 */ struct car_info? { ? ? char name[10]; ? ? // ?車(chē)牌 ? ? time_t time1; ? ? // ?入場(chǎng)時(shí)間 ? ? time_t time2; ? ? // ?出場(chǎng)時(shí)間 } ; typedef struct car_info CAR_I; /*停放,讓路順序棧結(jié)構(gòu)體 需要的參數(shù)為 :車(chē)牌號(hào),出場(chǎng)時(shí)間,入場(chǎng)時(shí)間 配套的子函數(shù) :初始化,判斷是否為空,出棧,入棧,查棧*/ struct sequencestack? { ? ? int top; ? ? CAR_I *date; } ; typedef struct sequencestack ST; /*隊(duì)列節(jié)點(diǎn)結(jié)構(gòu)體 需要的參數(shù)為 :車(chē)牌號(hào),下一個(gè)節(jié)點(diǎn)地址 */ struct car_wait? { ? ? char name[10]; ? ? struct car_wait *next; } ; typedef struct car_wait CAR_W; /*等候鏈?zhǔn)疥?duì)列結(jié)構(gòu) 需要的參數(shù)為 :頭指針,尾指針 配套的子函數(shù) :初始化,出隊(duì)列,入隊(duì)列 */ struct linkqueue? { ? ? CAR_W *front; ? ? CAR_W *rear; } ; typedef struct linkqueue LQ; /*存放所有信息的鏈表 需要的參數(shù)為:車(chē)牌號(hào),出入廠(chǎng)狀態(tài),入場(chǎng)時(shí)間,出場(chǎng)時(shí)間,下一個(gè)節(jié)點(diǎn)的地址 需要的函數(shù)為:初始化,入鏈表,查找數(shù)據(jù),遍歷打印 */ struct all_info? { ? ? char name[10]; ? ? char sit[10]; ? ? time_t time1; ? ? // ?入場(chǎng)時(shí)間 ? ? time_t time2; ? ? // ?出場(chǎng)時(shí)間 ? ? struct all_info *next; } ; typedef struct all_info A_INFO; int car_in(); int car_out(); int find_car(); int record_all(); int car_park(); int Car_wait(); int STinit(ST **q); int STempty(ST *q); int STinsert(ST *q, char na[] ,time_t time); int STout(ST *q,char *a, time_t *time); int LQinit(LQ **q); int LQinsert(LQ *q, char na[]); int LQout(LQ *q, char *a); int LLinit(A_INFO **q); int LLinsert(A_INFO *q, int n, char na[], char s[], time_t timeA, time_t timeB); int LLfind(A_INFO *q, char na[]); int LLget(A_INFO *q, int n, A_INFO **k); int LLtra(A_INFO *q); int parkadd(CAR_I car[], char na[], time_t time); int parkdel(CAR_I car[] ,char na[],time_t time); int print(CAR_I car[]); int park_init(); struct tm * local_time(time_t *tmpcal_ptr); int exchange(A_INFO *q, char na[], char s[]); #endif
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)易停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單的停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)游戲VIP停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言源碼實(shí)現(xiàn)停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)停車(chē)場(chǎng)管理
- C語(yǔ)言實(shí)現(xiàn)停車(chē)場(chǎng)管理系統(tǒng)
- C語(yǔ)言設(shè)計(jì)圖書(shū)登記系統(tǒng)與停車(chē)場(chǎng)管理系統(tǒng)的實(shí)例分享
- C語(yǔ)言課程設(shè)計(jì)之停車(chē)場(chǎng)管理問(wèn)題
相關(guān)文章
C語(yǔ)言二叉樹(shù)常見(jiàn)操作詳解【前序,中序,后序,層次遍歷及非遞歸查找,統(tǒng)計(jì)個(gè)數(shù),比較,求深度】
這篇文章主要介紹了C語(yǔ)言二叉樹(shù)常見(jiàn)操作,結(jié)合實(shí)例形式詳細(xì)分析了基于C語(yǔ)言的二叉樹(shù)前序,中序,后序,層次遍歷及非遞歸查找,統(tǒng)計(jì)個(gè)數(shù),比較,求深度等相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-04-04C++實(shí)現(xiàn)LeetCode(149.共線(xiàn)點(diǎn)個(gè)數(shù))
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(149.共線(xiàn)點(diǎn)個(gè)數(shù)),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07C++面試題之?dāng)?shù)a、b的值互換(不使用中間變量)
這篇文章主要介紹了不使用中間變量,C++實(shí)現(xiàn)數(shù)a、b的值互相轉(zhuǎn)換操作,感興趣的小伙伴們可以參考一下2016-07-07Clion(CMake工具)中引入第三方庫(kù)的詳細(xì)方法
這篇文章主要介紹了Clion(CMake工具)中引入第三方庫(kù)的詳細(xì)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02C++類(lèi)模板實(shí)戰(zhàn)之vector容器的實(shí)現(xiàn)
本文我們將做一個(gè)類(lèi)模板實(shí)戰(zhàn)-手寫(xiě)精簡(jiǎn)版vector容器。讓我們自己封裝一個(gè)數(shù)組類(lèi),可以適應(yīng)基本數(shù)據(jù)類(lèi)型和自定義數(shù)據(jù)類(lèi)型,感興趣的可以了解一下2022-07-07