當前位置:首頁 » 編程語言 » 航空客運訂票系統數據結構c語言
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

航空客運訂票系統數據結構c語言

發布時間: 2022-12-23 23:19:38

Ⅰ 正在學習c語言--數據結構,請大家來幫忙

既然有200分,肯定得花點功夫:
所有程序在win-tc和DEV-C++下都運行通過,代碼簡練,執行正確。
200分這多題,劃得來啊。請送分,謝謝。
第一題:
http://..com/question/80603134.html
第三題:
http://www.programfan.com/club/showtxt.asp?id=234730
這里還有固定密碼的詳細注釋程序:
http://..com/question/77796518.html
第四題:
程序超過10000字,無法上傳(這一個程序得200分)若有需要,留郵箱密我
第六題:
http://..com/question/79338502.html
第九題:
http://..com/question/80048763.html
第十題:
http://..com/question/79375216.html
第五題:遞歸演算法,不是你的要求。
第十二題:圖的廣度優先遍歷
/*******************************************/
/* 圖形的廣度優先搜尋法 */
/*******************************************/
#include <stdlib.h>
#include <stdio.h>
#define MAXQUEUE 10 /* 隊列的最大容量 */
struct node /* 圖的頂點結構定義 */
{
int vertex;
struct node *nextnode;
};
typedef struct node *graph; /* 圖的結構指針 */
struct node head[9]; /* 圖的頂點數組 */
int visited[9]; /* 遍歷標記數組 */
int queue[MAXQUEUE]; /* 定義序列數組 */
int front = -1; /* 序列前端 */
int rear = -1; /* 序列後端 */
/***********************二維數組向鄰接表的轉化****************************/
void creategraph(int node[20][2],int num)
{
graph newnode; /* 頂點指針 */
graph ptr;
int from; /* 邊起點 */
int to; /* 邊終點 */
int i;
for ( i = 0; i < num; i++ ) /* 第i條邊的信息處理 */
{
from = node[i][0]; /* 邊的起點 */
to = node[i][1]; /* 邊的終點 */
/* 建立新頂點 */
newnode = ( graph ) malloc(sizeof(struct node));
newnode->vertex = to; /* 頂點內容 */
newnode->nextnode = NULL; /* 設定指針初值 */
ptr = &(head[from]); /* 頂點位置 */
while ( ptr->nextnode != NULL ) /* 遍歷至鏈表尾 */
ptr = ptr->nextnode; /* 下一個頂點 */
ptr->nextnode = newnode; /* 插入第i個節點的鏈表尾部 */
}
}
/************************ 數值入隊列************************************/
int enqueue(int value)
{
if ( rear >= MAXQUEUE ) /* 檢查佇列是否全滿 */
return -1; /* 無法存入 */
rear++; /* 後端指標往前移 */
queue[rear] = value; /* 存入佇列 */
}
/************************* 數值出隊列*********************************/
int dequeue()
{
if ( front == rear ) /* 隊列是否為空 */
return -1; /* 為空,無法取出 */
front++; /* 前端指標往前移 */
return queue[front]; /* 從隊列中取出信息 */
}
/*********************** 圖形的廣度優先遍歷************************/
void bfs(int current)
{
graph ptr;
/* 處理第一個頂點 */
enqueue(current); /* 將頂點存入隊列 */
visited[current] = 1; /* 已遍歷過記錄標志置疑1*/
printf(" Vertex[%d]\n",current); /* 列印輸出遍歷頂點值 */
while ( front != rear ) /* 隊列是否為空 */
{
current = dequeue(); /* 將頂點從隊列列取出 */
ptr = head[current].nextnode; /* 頂點位置 */
while ( ptr != NULL ) /* 遍歷至鏈表尾 */
{
if ( visited[ptr->vertex] == 0 ) /*頂點沒有遍歷過*/
{
enqueue(ptr->vertex); /* 獎定點放入隊列 */
visited[ptr->vertex] = 1; /* 置遍歷標記為1 */

printf(" Vertex[%d]\n",ptr->vertex);/* 印出遍歷頂點值 */
}
ptr = ptr->nextnode; /* 下一個頂點 */
}
}
}
/*********************** 主程序 ************************************/
/*********************************************************************/
int main()
{
graph ptr;
int node[20][2] = { {1, 2}, {2, 1}, /* 邊信息數組 */
{6, 3}, {3, 6},
{2, 4}, {4, 2},
{1, 5}, {5, 1},
{3, 7}, {7, 3},
{1, 7}, {7, 1},
{4, 8}, {8, 4},
{5, 8}, {8, 5},
{2, 8}, {8, 2},
{7, 8}, {8, 7} };
int i;
clrscr();
puts("This is an example of Width Preferred Traverse of Gragh.\n");
for ( i = 1; i <= 8; i++ ) /*頂點結構數組初始化*/
{
head[i].vertex = i;
head[i].nextnode = NULL;
visited[i] = 0;
}
creategraph(node,20); /* 圖信息轉換,鄰接表的建立 */
printf("The content of the graph's allist is:\n");
for ( i = 1; i <= 8; i++ )
{
printf(" vertex%d =>",head[i].vertex); /* 頂點值 */
ptr = head[i].nextnode; /* 頂點位置 */
while ( ptr != NULL ) /* 遍歷至鏈表尾 */
{
printf(" %d ",ptr->vertex); /* 列印輸出頂點內容 */
ptr = ptr->nextnode; /* 下一個頂點 */
}
printf("\n"); /* 換行 */
}
printf("The contents of BFS are:\n");
bfs(1); /* 列印輸出遍歷過程 */
printf("\n"); /* 換行 */
puts(" Press any key to quit...");
getch();
return 0;
}

圖的深度優先遍歷
/***************************************************************/
/* 圖的深度優先遍歷 */
/***************************************************************/
#include <stdlib.h>
#include <stdio.h>
struct node /* 圖頂點結構定義 */
{
int vertex; /* 頂點數據信息 */
struct node *nextnode; /* 指下一頂點的指標 */
};
typedef struct node *graph; /* 圖形的結構新型態 */
struct node head[9]; /* 圖形頂點數組 */
int visited[9]; /* 遍歷標記數組 */
/********************根據已有的信息建立鄰接表********************/
void creategraph(int node[20][2],int num)/*num指的是圖的邊數*/
{
graph newnode; /*指向新節點的指針定義*/
graph ptr;
int from; /* 邊的起點 */
int to; /* 邊的終點 */
int i;
for ( i = 0; i < num; i++ ) /* 讀取邊線信息,插入鄰接表*/
{
from = node[i][0]; /* 邊線的起點 */
to = node[i][1]; /* 邊線的終點 */
/* 建立新頂點 */
newnode = ( graph ) malloc(sizeof(struct node));
newnode->vertex = to; /* 建立頂點內容 */
newnode->nextnode = NULL; /* 設定指標初值 */
ptr = &(head[from]); /* 頂點位置 */
while ( ptr->nextnode != NULL ) /* 遍歷至鏈表尾 */
ptr = ptr->nextnode; /* 下一個頂點 */
ptr->nextnode = newnode; /* 插入節點 */
}
}
/********************** 圖的深度優先搜尋法********************/
void dfs(int current)
{
graph ptr;
visited[current] = 1; /* 記錄已遍歷過 */
printf("vertex[%d]\n",current); /* 輸出遍歷頂點值 */
ptr = head[current].nextnode; /* 頂點位置 */
while ( ptr != NULL ) /* 遍歷至鏈表尾 */
{
if ( visited[ptr->vertex] == 0 ) /* 如過沒遍歷過 */
dfs(ptr->vertex); /* 遞回遍歷呼叫 */
ptr = ptr->nextnode; /* 下一個頂點 */
}
}
/****************************** 主程序******************************/
int main()
{
graph ptr; /* 邊線數組 */
int node[20][2] = { {1, 2}, {2, 1},
{1, 3}, {3, 1},
{1, 4}, {4, 1},
{2, 5}, {5, 2},
{2, 6}, {6, 2},
{3, 7}, {7, 3},
{4, 7}, {4, 4},
{5, 8}, {8, 5},
{6, 7}, {7, 6},
{7, 8}, {8, 7} };
int i;
clrscr();
for ( i = 1; i <= 8; i++ ) /* 頂點數組初始化 */
{
head[i].vertex = i; /* 設定頂點值 */
head[i].nextnode = NULL; /* 指針為空 */
visited[i] = 0; /* 設定遍歷初始標志 */
}
creategraph(node,20); /* 建立鄰接表 */
printf("Content of the gragh's ADlist is:\n");
for ( i = 1; i <= 8; i++ )
{
printf("vertex%d ->",head[i].vertex); /* 頂點值 */
ptr = head[i].nextnode; /* 頂點位置 */
while ( ptr != NULL ) /* 遍歷至鏈表尾 */
{
printf(" %d ",ptr->vertex); /* 印出頂點內容 */
ptr = ptr->nextnode; /* 下一個頂點 */
}
printf("\n"); /* 換行 */
}
printf("\nThe end of the dfs are:\n");
dfs(1); /* 列印輸出遍歷過程 */
printf("\n"); /* 換行 */
puts(" Press any key to quit...");
getch();
return 0;
}

Ⅱ 數據結構課程設計——航空訂票系統(C語言)

1、任務:航空客運定票的業務活動包括:查詢航線、客票預定和辦理退票等。試設計一個航空客運定票系統,以使上述業務可以藉助計算機來完成。 2、功能要求: 1) 錄入:可以錄入航班情況(數據可以存儲在一個數據文件中,數據結構、具 體數據自定) 2) 查詢:可以查詢某個航線的情況(如,輸入航班號,查詢起降時間,起飛抵 達城市,航班票價,票價折扣,確定航班是否滿倉);可以輸入起飛抵達城市, 查詢飛機航班情況; 3) 訂票:(訂票情況可以存在一個數據文件中,結構自己設定)可以訂票,如果 該航班已經無票,可以提供相關可選擇航班; 4) 退票: 可退票,退票後修改相關數據文件; 5) 客戶資料:有姓名,證件號,訂票數量及航班情況,訂單要有編號; 6) 修改航班信息:當航班信息改變可以修改航班數據文件。 3、要有一個好的界面~~~~~~~~~~~~~~~~~~~~~~~~4、需求分析 系統需求(系統要求實現的功能的具體情況)5、 概要設計 系統分析(分析系統的功能和具體模塊的劃分) 系統流程(系統的流程圖) 程序詳細代碼:

Ⅲ 數據結構實習 C語言 航空訂票系統

代碼如下:(但是不是跟你的要求完全相同,你改改吧!)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NAME_MAX 100//書的名字的最長字數
#define WRITER_MAX 100//作者名字的最長
#define PUB_MAX 100//出版單位最長名字
#define TIME 100//出版時間
typedef struct books
{
int loading;
char name[NAME_MAX];
char writer[WRITER_MAX];
int identify;
char pub[PUB_MAX];
char time[TIME];
int price;
struct books * next;
}book;

//頭結點不存儲信息
void Init(book * head)
{
head->next=NULL;
}
//列印一些歡迎詞之類的。。。。。
void welcome()
{
printf("******歡迎使用@@@@圖書館,哈哈*********\n");
printf("\n\n");
printf("1:圖書信息錄入功能\n");
printf("2:圖書信息瀏覽功能,顯示該書的所有信息\n");
printf("3:圖書信息查詢功能:按書名查詢與按作者名查詢\n");
printf("4:圖書信息的修改和刪除,可對相應數據進行修改和刪除\n");
}
//顯示一本書的信息
void print_the_book(book * p1)
{
printf("loading number:%d \n",p1->loading);
printf("name: ");
puts(p1->name);
printf(" \n");
printf("writer: ");
puts(p1->writer);
printf(" \n");
printf("identify:%d ***\n",p1->identify);
printf(" \n");
printf("pub: ");
puts(p1->pub);
printf(" \n");
printf("time: ");
puts(p1->time);
printf(" \n");
printf("price:%d ***\n",p1->price);
}
int chongfu(book * head,book * p)
{
book * p1=head->next;
int a=0;
while(p1!=NULL)
{
if(strcmp(p1->name,p->name)==0)
{
if(strcmp(p1->writer,p->writer)==0)
{
a=1;
break;
}
}
else
p1=p1->next;
}
return a;
}
//錄入一些信息。。。。
void luru(book * head)
{
book * p1=head;
book * p2;

//尋找NULL前的那個點
while(p1->next!=NULL)
{
p1=p1->next;
}

int a;
do
{
p2=(book *)malloc(sizeof(book));
printf("輸入書本信息\n");
printf("登錄號\n");
fflush(stdin);
scanf("%d",&p2->loading);
printf("書名\n");
fflush(stdin);
gets(p2->name);
fflush(stdin);
printf("作者\n");
gets(p2->writer);
fflush(stdin);
printf("分類號\n");
scanf("%d",&p2->identify);
fflush(stdin);
printf("出版社\n");
gets(p2->pub);
fflush(stdin);
printf("出版時間\n");
gets(p2->time);
fflush(stdin);
printf("價格\n");
scanf("%d",&p2->price);
p2->next=NULL;
fflush(stdin);
//加入鏈表
if(chongfu(head,p2))
printf("錄入信息重復\n");
else
{
p1->next=p2;
p1=p2;
}
printf("還想繼續錄入信息嗎?\n(1:繼續 0:停止)\n");
scanf("%d",&a);
}while(a==1);
}
void liulan(book * head)
{
book * p1=head->next;
int i=1;
while(p1!=NULL)
{
printf("*********第%d本書***********\n",i++);
print_the_book(p1);
p1=p1->next;
}
}
//查詢。。。。
void chaxun(book * head)
{
printf("按書名查詢還是按作者名查詢?\n(1:按書名查詢 0:按作者名查詢)\n");
book * p=head->next;
int a;
scanf("%d",&a);
int num=0;
char cha[NAME_MAX];
switch(a)
{
case 1:
printf("輸入書名:\n");
gets(cha);
while(p!=NULL)
{
if(strcmp(p->name,cha)==0)
{
num++;
print_the_book(p);
}
p=p->next;
}
break;
case 2:
printf("輸入作者名:\n");
gets(cha);
while(p!=NULL)
{
if(strcmp(p->writer,cha)==0)
{
num++;
print_the_book(p);
}
p=p->next;
}
}
if(num==0)
printf("無符合書本\n");
}
//修改信息
void xiugai(book * head)
{
printf("輸入需要修改書本的名稱和作者:\n");
char name_book[NAME_MAX];
char writer_book[WRITER_MAX];
printf("書本名稱:");
gets(name_book);
gets(writer_book);
book * p1=head->next;
int a=0;
while(p1!=NULL)
{
if(strcmp(p1->name,name_book)==0)
{
if(strcmp(p1->writer,writer_book)==0)
{
a=1;
break;
}
}
}
if(a==0)
printf("沒有這本書。。。\n");
else
{
print_the_book(p1);
printf("輸入新信息\n");
scanf("%d",&p1->loading);
gets(p1->name);
gets(p1->writer);
scanf("%d",&p1->identify);
gets(p1->pub);
gets(p1->time);
scanf("%d",&p1->price);
}
}
void main()
{
book * head;
head=(book *)malloc(sizeof(book));
Init(head);
int contin=1;
while(contin)
{
welcome();
printf("想進行哪項操作?\n");
int a;
scanf("%d",&a);
switch(a)
{
case 1:
luru(head);
break;
case 2:
liulan(head);
break;
case 3:
chaxun(head);
break;
case 4:
xiugai(head);
}
printf("繼續使用圖書館還是退出?\n(1:continue 0:exit)\n");
scanf("%d",&contin);
}
}

Ⅳ 飛機訂票系統設計 c語言

(已修改,請用最新的代碼)代碼說明:

1級菜單:選擇購買的航班號,並顯示對應座位狀態。

(我只做測試,所以初始化initFlight函數中我只初始了2個航班,需要自己按照我的代碼添)

(注意:實際開發軟體,鏈表數據是從資料庫中讀取的,需要實時同步,如果要多次調用initFlight函數,記得自己寫一個釋放內存的函數,把所有鏈表「SINFO和FLINFO」節點都釋放掉,釋放函數我沒寫,需要你自己寫!!!)

2級菜單:選擇購買對應座位號,完成購買,並實時顯示購買結果。

位置編號、座位最大排數、艙室類型、折扣等參數均由常量參數空值,需要修改自行改常量。

注意:艙室類型(我默認3個類型頭等艙、公務艙、經濟艙)對應折扣參數:tDiscount二維數組。如要如要添加新的艙室類型,必須將參數常量TYPESIZE、typeName、types、tDiscount這4個同時修改,具體看代碼備注!!

座位票價=基礎票價*類型折扣*時段折扣。

因為飛機不讓吸煙,所以我沒做吸煙區(笑),如果你需要,可以作為類型自行添加!

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<malloc.h>
#include<time.h>
//-----------------------相關參數,想改變,在這里修改!!!!!!!-----------------------------
constfloattimeDiscount=1;//時段折扣,影響所有航班最終價格,默認1
constcharcID[5]="ABCD";//位置編號
constintmaxRow=20;//位置最大排號
//注意:如果修改類型數量,types和tDiscount必須同時修改!!!
#defineTYPESIZE3//類型數量
constchartypeName[TYPESIZE][10]={"頭等艙","公務艙","經濟艙"};
constinttypes[TYPESIZE][2]={{1,2},{3,4},{5,20}};//排號對應類型。1~2排頭等艙,3~4排公務艙,5~20排經濟艙
constfloattDiscount[TYPESIZE]={1.5,1.3,1};//類型折扣。頭等艙1.5倍,公務艙1.3倍,經濟艙1倍

//-------------------------------------------------------------------------------
typedefstructseatInfo//座位信息,一條鏈表對應一個航班信息,鏈表順序從第一排左邊第一個開始往後A1~D1,A2~D2。。。
{
charcloID;//位置編號A、B、C、D
introw;//位置排號
inttype;//座位所屬類型:0:頭等艙、1:公務艙、2:經濟艙,不同類型對應不同的類型折扣tDiscount
intsell;//出售狀態,0:未出售;1:已出售
structseatInfo*next;
}SINFO;
typedefstructflightInfo//航班信息
{
charfid[10];//航班號
time_ttfTime;//起飛時間
time_tldTime;//降落時間
chartoCity[20];//抵達城市
floattPrice;//基礎票價,不同位置具有不同折扣,座位票價=基礎票價*類型折扣*時段折扣
structflightInfo*next;
structseatInfo*sHead;//對應座位鏈表的頭節點
}FLINFO;
voidmeError(void*p);
SINFO*getSINFO();//獲取座位鏈表
//addFLINFO:添加航班信息鏈表的節點flinfoHead:頭節點(第一次傳NULL會自動生成),flinfoTail:尾節點,fNew:要添加的結構信息(成員指針無需賦值)
FLINFO*addFLINFO(FLINFO**ffHead,FLINFO*flinfoTail,FLINFOfNew);//返回尾節點
time_tgetTime_tfromStr(char*sTime);//將YYYY-MM-DDhh:mm:ss格式的時間字元串轉換成time_t型數值
FLINFO*initFlight();//初始化航班信息,返回航班鏈表頭節點,如果想手動輸入,請在這里添加!!!正常軟體開發,這一步應該是從資料庫讀取!
char*getTString(structtm*tm0);//通過tm獲取時間字元串
voidshowSinfo(FLINFO*flinfo);//顯示航班對應座位信息
voidprintfFlinfo(FLINFO*flinfoHead);
FLINFO*selectFlinfo(FLINFO*flinfoHead,char*fid);//選擇航班號,返回節點
voidshowSinfo(FLINFO*flinfo);//顯示航班對應座位信息
SINFO*selectSinfo(FLINFO*flinfo,char*sid);//選擇座位,返回節點
intmain()
{
FLINFO*flinfoHead=initFlight(),*ffSelect=NULL;
SINFO*sfSelect=NULL;
charfid[10]={0},sid[10]={10};
while(1)
{
ffSelect=NULL;
sfSelect=NULL;
memset(fid,0,10);
memset(sid,0,10);
printfFlinfo(flinfoHead);
printf("請輸入要購買的航班號:");
scanf("%s",fid);
ffSelect=selectFlinfo(flinfoHead,fid);
if(!ffSelect)
{
printf("未找到對應航班,按任意鍵繼續----- ");
getch();
system("cls");
continue;
}
system("cls");
printf("航班號:%s座位信息如下: ",ffSelect->fid);

showSinfo(ffSelect);
printf("請輸入要購買的座位編號(輸入0返回主菜單):");
scanf("%s",sid);
if(!strcmp(sid,"0"))
{
system("cls");
continue;
}
else
{
sfSelect=selectSinfo(ffSelect,sid);
if(!sfSelect||sfSelect->sell)
{
printf("未找到對應座位或該座位已出售,請重新輸入!按任意鍵繼續----- ");
getch();
system("cls");
continue;
}
printf("購買成功!按任意鍵繼續-----");
sfSelect->sell=1;
getch();
system("cls");
}

}
return0;
}
SINFO*selectSinfo(FLINFO*flinfo,char*sid)//選擇座位,返回節點
{
SINFO*sinfoHead=flinfo->sHead;
while(sinfoHead->next)
{
if(sinfoHead->next->cloID==sid[0]&&sinfoHead->next->row==atoi(sid+1))
returnsinfoHead->next;
sinfoHead=sinfoHead->next;
}
returnNULL;
}
voidshowSinfo(FLINFO*flinfo)//顯示航班對應座位信息
{
SINFO*sinfoHead=flinfo->sHead,*sfp=NULL;
inti,j,k,row=maxRow,clo=strlen(cID);
chartypeStr[10]={0};
for(i=0;i<row;i++)
{
//---------讀取座位所屬艙室------------
memset(typeStr,0,10);
for(k=0;k<TYPESIZE;k++)
if(i+1>=types[k][0]&&i+1<=types[k][1])
strcpy(typeStr,typeName[k]);
//--------------------------------------
printf(" ");
for(j=0;j<clo;j++)
printf("-------------");
printf(" ");
sfp=sinfoHead;

for(j=0;j<clo;j++)
{
printf("|%c%02d|",sfp->next->cloID,sfp->next->row);
sfp=sfp->next;
}
printf(" ");
sfp=sinfoHead;
for(j=0;j<clo;j++)
{
printf("|%c|",sfp->next->sell?2:1);
sfp=sfp->next;
}
printf(" ");
sfp=sinfoHead;
for(j=0;j<clo;j++)
{
printf("|%6s:%4.0f|",typeStr,flinfo->tPrice*tDiscount[sfp->next->type]*timeDiscount);
sfp=sfp->next;
}
printf(" ");
sinfoHead=sfp;
}
for(j=0;i<clo;j++)
printf("-------");
printf(" ");

}
FLINFO*selectFlinfo(FLINFO*flinfoHead,char*fid)//選擇航班號,返回節點
{
while(flinfoHead->next)
{
if(!strcmp(flinfoHead->next->fid,fid))
returnflinfoHead->next;
flinfoHead=flinfoHead->next;
}
returnNULL;
}
voidprintfFlinfo(FLINFO*flinfoHead)
{
while(flinfoHead->next)
{
printf("目的地:%s,航班號:%s ----起飛時間:%s,抵達時間:%s ",flinfoHead->next->toCity,flinfoHead->next->fid,getTString(localtime(&flinfoHead->next->tfTime)),getTString(localtime(&flinfoHead->next->ldTime)));
flinfoHead=flinfoHead->next;
}
}
char*getTString(structtm*tm0)//通過tm獲取時間字元串
{
char*str=(char*)malloc(sizeof(char)*20),num[5]={0};
meError(str);
memset(str,0,20);
sprintf(num,"%4d",tm0->tm_year+1900);
strcat(str,num);
strcat(str,"-");

memset(num,0,5);
sprintf(num,"%02d",tm0->tm_mon);
strcat(str,num);
strcat(str,"-");

memset(num,0,5);
sprintf(num,"%02d",tm0->tm_mday);
strcat(str,num);
strcat(str,"");

memset(num,0,5);
sprintf(num,"%02d",tm0->tm_hour);
strcat(str,num);
strcat(str,":");

memset(num,0,5);
sprintf(num,"%02d",tm0->tm_min);
strcat(str,num);
strcat(str,":");

memset(num,0,5);
sprintf(num,"%02d",tm0->tm_sec);
strcat(str,num);
returnstr;
}
time_tgetTime_tfromStr(char*sTime)//將YYYY-MM-DDhh:mm:ss格式的時間字元串轉換成time_t型數值
{
time_trt;
structtm*tm1=NULL;
rt=time(NULL);
tm1=localtime(&rt);
sscanf(sTime,("%4d-%2d-%2d%2d:%2d:%2d"),&tm1->tm_year,&tm1->tm_mon,&tm1->tm_mday,&tm1->tm_hour,&tm1->tm_min,&tm1->tm_sec);
tm1->tm_year-=1900;
tm1->tm_mon--;
rt=mktime(tm1);

returnrt;

}
FLINFO*initFlight()//初始化航班信息,返回航班鏈表頭節點,如果想手動輸入,請在這里添加!!!正常軟體開發,這一步應該是從資料庫讀取!
{
FLINFO*ffHead=NULL,*flinfoTail=NULL,fNew;
//--------添加一個航班信息----需要增加按照我下面調用方式寫--------------------------------
strcpy(fNew.fid,"CI502");
fNew.tfTime=getTime_tfromStr("2019-02-2003:30:30");
fNew.ldTime=getTime_tfromStr("2019-02-2005:20:30");
strcpy(fNew.toCity,"台北");
fNew.tPrice=1000;
fNew.next=NULL;
flinfoTail=addFLINFO(&ffHead,flinfoTail,fNew);
//--------------------------------------------------------------------------------------------
strcpy(fNew.fid,"9C8921");
fNew.tfTime=getTime_tfromStr("2019-02-2014:30:30");
fNew.ldTime=getTime_tfromStr("2019-02-2016:40:30");
strcpy(fNew.toCity,"香港");
fNew.tPrice=500;
fNew.next=NULL;
flinfoTail=addFLINFO(&ffHead,flinfoTail,fNew);
returnffHead;
}
FLINFO*addFLINFO(FLINFO**ffHead,FLINFO*flinfoTail,FLINFOfNew)//返回尾節點
//添加航班信息鏈表的節點flinfoHead:頭節點(第一次傳NULL會自動生成),flinfoTail:尾節點,fNew:要添加的結構信息(成員指針無需賦值)
{
FLINFO*flinfoHead=*ffHead;
if(flinfoHead==NULL)
{
*ffHead=(FLINFO*)malloc(sizeof(FLINFO));
flinfoHead=*ffHead;
meError(flinfoHead);
flinfoHead->next=NULL;
}
FLINFO*flinfoNew=(FLINFO*)malloc(sizeof(FLINFO));
meError(flinfoNew);
flinfoNew->next=NULL;
flinfoNew->fid[0]=0;
strcpy(flinfoNew->fid,fNew.fid);
flinfoNew->ldTime=fNew.ldTime;
flinfoNew->tfTime=fNew.tfTime;
flinfoNew->toCity[0]=0;
strcpy(flinfoNew->toCity,fNew.toCity);
flinfoNew->tPrice=fNew.tPrice;
flinfoNew->sHead=getSINFO();
if(flinfoHead->next==NULL)
flinfoHead->next=flinfoNew;
else
flinfoTail->next=flinfoNew;
flinfoTail=flinfoNew;
returnflinfoTail;
}
SINFO*getSINFO()//獲取座位鏈表
{
intmaxClo=strlen(cID),cnt=maxClo*maxRow,clo=0,row=1,i;
SINFO*sinfoHead=(SINFO*)malloc(sizeof(SINFO)),*sinfoTail=NULL;
meError(sinfoHead);
sinfoHead->next=NULL;
SINFO*sinfoNew=NULL;
while(cnt--)//按順序生成對應數量的座位鏈表
{
if(clo==maxClo)
clo=0,row++;
if(row==maxRow+1)
row=1;

sinfoNew=(SINFO*)malloc(sizeof(SINFO));
meError(sinfoNew);
sinfoNew->cloID=cID[clo];
sinfoNew->row=row;
for(i=0;i<TYPESIZE;i++)
if(row>=types[i][0]&&row<=types[i][1])
{
sinfoNew->type=i;
break;
}
sinfoNew->sell=0;
sinfoNew->next=NULL;
if(sinfoHead->next==NULL)
sinfoHead->next=sinfoNew;
else
sinfoTail->next=sinfoNew;
sinfoTail=sinfoNew;
clo++;
}
returnsinfoHead;
}
voidmeError(void*p)//內存申請失敗
{
if(p==NULL)
{
printf(" 異常:內存申請失敗!回車結束程序! ");
while(getch()!=' ');
exit(0);
}
}