页眉内容
fscanf(fp,\
AdjList[j].Flight[AdjList[j].FlightNum].Cost=cost; AdjList[j].FlightNum++; }
(12)找出最快路线:
int SearchMinTime (CityType City,CityType EndCity,int CurTime,int curPathNo,int TravelType) {
int i;
if (City==EndCity)
{
{
{
if (MinTime>CurTime-StartTime) for (i=0;i<=curPathNo;i++)
MinPath[i].City=Path[i].City; MinPath[i].TraNo=Path[i].TraNo; curPath=curPathNo;
} {
}
}
MinTime=CurTime-StartTime;
} return 1;
fclose(fp);
else
curPathNo++;
Path[curPathNo].City=City; if (!TravelType)
{
{
for (i=0;i ((AdjList[City].Train[i].StartTime>=(CurTime40))&&(AdjList[City].Train[ 41 页脚内容 页眉内容 i].StopTime+(CurTime/1440)*1440-StartTime { Path[curPathNo].TraNo=i; SearchMinTime(AdjList[City].Train[i].EndCity,EndCity,AdjList[City].Train[i].StopTime+(CurTime/1440)*1440,curPathNo,TravelType); } if ((AdjList[City].Train[i].StartTime<(CurTime40))&&(AdjList[City].Train[i].StopTime+(CurTime/1440)*1440-StartTime { Path[curPathNo].TraNo=i; SearchMinTime(AdjList[City].Train[i].EndCity,EndCity,AdjList[City].Train[i].StopTime+(CurTime/1440+1)*1440,curPathNo,TravelType); } } } { { else for (i=0;i ((AdjList[City].Flight[i].StartTime>=CurTime)&&(AdjList[City].Flight[i].StopTime+(CurTime/1440)*1440-StartTime { Path[curPathNo].TraNo=i; SearchMinTime(AdjList[City].Flight[i].EndCity,EndCity,AdjList[City].Flight[i].StopTime+(CurTime/1440)*1440,curPathNo,TravelType); } if ((AdjList[City].Flight[i].StartTime 41 页脚内容 页眉内容 me+(CurTime/1440)*1440-StartTime { Path[curPathNo].TraNo=i; SearchMinTime(AdjList[City].Flight[i].EndCity,EndCity,AdjList[City].Flight[i].StopTime+(CurTime/1440+1)*1440,curPathNo,TravelType); } (13)计算最快路线所需时间并打印: int CalcMinTime (int StartCity,int EndCity,int TravelType) { int i; int startH, startM, endH, endM;//定义四个变量:startH 出发的小 时,startM 出发的分钟, endH 到达的小时, endM 到达的分钟 MinTime=32767;curPath=0; Path[0].City=StartCity; if (!TravelType) { { for (i=0;i StartTime=AdjList[StartCity].Train[i].StartTime; SearchMinTime(AdjList[StartCity].Train[i].EndCity,EndCity,AdjList[StartCity].Train[i].StopTime,0,TravelType); } { } } } } } return 1; else for (i=0;i 41 页脚内容 页眉内容 { Path[0].TraNo=i; StartTime=AdjList[StartCity].Flight[i].StartTime; SearchMinTime(AdjList[StartCity].Flight[i].EndCity,EndCity,AdjList[StartCity].Flight[i].StopTime,0,TravelType); } { } if (MinTime==32767) printf(\ return 0; } // if (!TravelType) // StartTime=AdjList[StartCity].Train[MinPath[0].TraNo].StartTime; // else // StartTime=AdjList[StartCity].Flight[MinPath[0].TraNo].StartTime; printf(\ for (i=0;i<=curPath;i++) { : %s if (!TravelType) printf(\].name); else printf(\].name); startH startM = = AdjList[MinPath[i].City].Train[MinPath[i].TraNo].StartTime / 60 ; AdjList[MinPath[i].City].Train[MinPath[i].TraNo].StartTime % 60 ; 41 \ : %s \ 页脚内容 页眉内容 endH endM = = AdjList[MinPath[i].City].Train[MinPath[i].TraNo].StopTime / 60 ; AdjList[MinPath[i].City].Train[MinPath[i].TraNo].StopTime % 60 ; if( !(startH/10) ) { printf(\ } printf(\ if( !(startM/10) ) { printf(\ } printf(\ if( !(endH/10) ) { printf(\ } printf(\ if( !(endM/10) ) { printf(\ } printf(\ //printf(\ } printf(\ printf(\Cost: - hour minute\ return 1; } 页脚内容 41 - -