全国交通咨询模拟系统实验报告

页眉内容

return 1; }

(5)删除城市: int DelCity (char *Name) {

int city,i,j;

city=SeekCity(Name); for (i=city;i

{

strcpy(CityName[i],CityName[i+1]);

AdjList[i].FlightNum=AdjList[i+1].FlightNum; AdjList[i].TrainNum=AdjList[i+1].TrainNum; for (j=0;j

{

AdjList[i].Flight[j].Cost=AdjList[i+1].Flight[j].Cost;

AdjList[i].Flight[j].EndCity=AdjList[i+1].Flight[j].EndCity;

strcpy(AdjList[i].Flight[j].name,AdjList[i+1].Flight[j].name);

AdjList[i].Flight[j].StartTime=AdjList[i+1].Flight[j].StartTime;

AdjList[i].Flight[j].StopTime=AdjList[i+1].Flight[j].StopTime;

} }

CityNum--; return 1; }

(6)添加火车路线:

int InsertTrain (char *train,char *StartCity,char *EndCity,int StartTime,int EndTime,int cost) {

int i,j;

i=SeekCity(StartCity); j=SeekCity(EndCity);

41

页脚内容

页眉内容

AdjList[i].Train[AdjList[i].TrainNum].Cost=cost; AdjList[i].Train[AdjList[i].TrainNum].EndCity=j;

AdjList[i].Train[AdjList[i].TrainNum].StartTime=StartTime; AdjList[i].Train[AdjList[i].TrainNum].StopTime=EndTime; strcpy(AdjList[i].Train[AdjList[i].TrainNum].name,train); AdjList[i].TrainNum++; return 1; }

(7)添加航班路线:

int InsertFlight(char *flight,char *StartCity,char *EndCity,int StartTime,int EndTime,int cost) {

int i,j;

i=SeekCity(StartCity); j=SeekCity(EndCity);

AdjList[i].Flight[AdjList[i].FlightNum].Cost=cost; AdjList[i].Flight[AdjList[i].FlightNum].EndCity=j;

AdjList[i].Flight[AdjList[i].FlightNum].StartTime=StartTime; AdjList[i].Flight[AdjList[i].FlightNum].StopTime=EndTime; strcpy(AdjList[i].Flight[AdjList[i].FlightNum].name,flight); AdjList[i].FlightNum++; return 1; }

(8)删除路线: int DelPath (char *name) {

int i,j,flag=0;

for (i=0;i

{

for (j=0;j

if (strcmp(AdjList[i].Flight[j].name,name)==0)

{

break;

flag=1;

}

41

页脚内容

页眉内容

if (flag)

{

{

for (;j

AdjList[i].Flight[j].Cost=AdjList[i].Flight[j+1].Cost;

AdjList[i].Flight[j].EndCity=AdjList[i].Flight[j+1].EndCity;

strcpy(AdjList[i].Flight[j].name,AdjList[i].Flight[j+1].name);

AdjList[i].Flight[j].StartTime=AdjList[i].Flight[j+1].StartTime;

AdjList[i].Flight[j].StopTime=AdjList[i].Flight[j+1].StopTime;

}

} break;

AdjList[i].FlightNum--;

for (j=0;j

if (strcmp(AdjList[i].Train[j].name,name)==0)

{

{

{ }

flag=1;break; if (flag)

for (;j

AdjList[i].Train[j].Cost=AdjList[i].Train[j+1].Cost;

AdjList[i].Train[j].EndCity=AdjList[i].Train[j+1].EndCity;

strcpy(AdjList[i].Train[j].name,AdjList[i].Train[j+1].name);

AdjList[i].Train[j].StartTime=AdjList[i].Train[j+1].StartTime;

41

页脚内容

页眉内容

AdjList[i].Train[j].StopTime=AdjList[i].Train[j+1].StopTime; }

(9)打印最小费用路线: void {

int track[Dij_MAXN]; int i=0,j,k,min,tmp,end,cost=0;

int startH, startM, endH, endM;//定义四个变量:startH 出发的小时,

startM 出发的分钟, endH 到达的小时, endM 到达的分钟

j=p_end;track[i++]=j; while (PreCity[j]>=0)

{

cost+=matx[PreCity[j]][j]; track[i++]=j=PreCity[j];

}

printf(\ if (!TravelType)

{

{

printf(\ end=track[i-1];min=32767;

for (k=0;k

if

for(i--;i>0;i--)

Dijkstra_Output(int

matx[Dij_MAXN][Dij_MAXN],int

PreCity[Dij_MAXN],int p_end,int TravelType)

}

}

} break;

AdjList[i].TrainNum--;

return 1;

(AdjList[track[i]].Train[k].EndCity==end&&min>AdjList[track[i]].Train[k].Co

41

页脚内容

页眉内容

st)

41

{ }

min=AdjList[track[i]].Train[k].Cost; tmp=k;

printf(\ \ startH = AdjList[track[i]].Train[tmp].StartTime/60 ; startM = AdjList[track[i]].Train[tmp].StartTime`; endH = AdjList[track[i]].Train[tmp].StopTime/60 ; endM = AdjList[track[i]].Train[tmp].StopTime` ; if( !(startH/10) ) {

printf(\ }

printf(\ if( !(startM/10) ) {

printf(\ }

printf(\ if( !(endH/10) ) {

printf(\ }

printf(\ if( !(endM/10) ) {

printf(\ }

printf(\

页脚内容

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4