#include
#include
#include
#define MaxVerNum 100//最大结点个数
#define INF 65535
#define MM "2222"
using namespace std;
typedef char VertexType;//图中顶点的数据类型
typedef int eInfoType;//权值的数据类型
//栈
typedef struct IsNode
{
int data;
struct IsNode * inext;
}sNode;
//时间
typedef struct
{
int hours;
char synbol;
int minutes;
}Time;
//班次
typedef struct
{
int divisions;//班次
Time firstBusTime;//首班车的出发时间
}schedules;
typedef schedules Schedules[MaxVerNum];
//城市
typedef struct node//边链表节点
{
int adjvex;
eInfoType eInfo;
struct node * next;
}EdgeNode;
typedef struct//顶点表节点
{
VertexType vertex[20];
EdgeNode * firstedge;
}VertexNode;
typedef VertexNode AdjList[MaxVerNum];
typedef struct
{
AdjList adjlist;
int n,e;
}ALGraph;
//火车
typedef struct trainTime
{
int trainName;
int time;
int stopTime;
int money;
int distance;
struct trainTime * nextStation;
}train;
typedef struct
{
int trainName;
train * trainRoute;
}trainN;
typedef trainN trainS[MaxVerNum];
typedef struct
{
trainS trainSchedule;
int m;
Schedules Train;
}trainlist;
//飞机
typedef struct planeTime
{
int planeName;
int platime;
int plastoptime;
int plamoney;
int pladistance;
struct planeTime * planextStation;
}plane;
typedef struct
{
int planeName;
plane * planeRoute;
}planeN;
typedef planeN planeS[MaxVerNum];
typedef struct
{
planeS planeSchedule;
int x;
Schedules Plane;
}planelist;
//函数声明
void create(ALGraph * & G);
void printA(ALGraph * G);
void new_line();
void createTrainSchedule(ALGraph * G,trainlist * & T,int **,int **);
void printTrain(ALGraph * G,trainlist * T);
void createplaneSchedule(ALGraph * G,planelist * & H,int **,int **);
void printplane(ALGraph * G,planelist * H);
void administrator(ALGraph * G,trainlist * T,planelist * H,int **,int **,int **,int **,int **,int **,int **,int **);
void user();
void establishFigure(ALGraph * G);
void estFigure(ALGraph * G);
void establishTrain(ALGraph * G,trainlist * T,int **,int **);
void estTrain(ALGraph * G,trainlist * T,int **,int **);
void establishPlane(ALGraph * G,planelist * H,int **,int **);
void estPlane(ALGraph * G,planelist * H,int **,int **);
void printTime(ALGraph * G,trainlist * T);
void initializeTrainPathMatrix(ALGraph * G,int **,int **);
void createTrainPathMatrix(trainlist * T,int **,int **,int *,int num,int k);
void printTrainPathMatrix(ALGraph * G,int **,int **,int *);
void trainFloyd(ALGraph * G,int **,int **,int **);
void initialStack(sNode * & top);
void pushStack(sNode * & top,int x);
void popStack(sNode * & top,int &x);
void printTFloyd(ALGraph * G,int **,int **);
void estffile(ALGraph * &G);
void estffileTrain(ALGraph * G,trainlist * & T,int **,int **);//文件输入建立火车时刻表
void initializePlanePathMatrix(ALGraph * G,int **,int **);
void createPlanePathMatrix(planelist * H,int **,int **,int *,int num,int k);
void printPlanePathMatrix(ALGraph * G,int **,int **,int *);
void estffilePlane(ALGraph * G,planelist * & H,int **,int **);
void addCity(ALGraph * &G);
void deleteCity(ALGraph * &G);
void addTrainPath(ALGraph * G,trainlist * & T,int **,int **);
void deleteTrainPath(ALGraph * G,trainlist * & T,int **,int **);
void addPlanePath(ALGraph * G,planelist * & T,int **,int **);
void deletePlanePath(ALGraph * G,planelist * & H,int **,int **);
void printPlane(ALGraph * G,planelist * H);
//输入、输出流声明
ifstream in_stream;
ofstream out_stream;
//主函数
int main()
{
int num,i;
char n[5];
ALGraph * G=(ALGraph *)malloc(sizeof(ALGraph));
trainlist * T=(trainlist *)malloc(sizeof(trainlist));
planelist * H=(planelist *)malloc(sizeof(planelist));
int **trainPath=new int * [MaxVerNum];
for(i=0;i
int ** tmPath=new int *[MaxVerNum];
for(i=0;i
int ** tmDisk=new int *[MaxVerNum];
for(i=0;i
int ** tPath=new int *[MaxVerNum];
for(i=0;i
int **planePath=new int * [MaxVerNum];
for(i=0;i
int ** pmPath=new int *[MaxVerNum];
for(i=0;i
int ** pmDisk=new int *[MaxVerNum];
for(i=0;i
int ** pPath=new int *[MaxVerNum];
for(i=0;i
do
{
cout<
cout<
cin>>num;
switch(num)
{
case 1:do
{
cout<<" 请输入密码:";
cin>>n;
}while(strcmp(n,MM));
administrator(G,T,H,trainPath,tmPath,tPath,tmDisk,planePath,pmPath,pPath,pmDisk);
break;
/*case 2:user();
break;*/
}
}while(num!=3);
cout<
}
//管理员函数
void administrator(ALGraph * G,trainlist * T,planelist * H,int ** trainPath,int ** tmPath,int ** tPath,int ** tmDisk,int ** planePath,int ** pmPath,int ** pPath,int ** pmDisk)
{
int i;
do
{
cout<
cin>>i;
switch(i)
{
case 1:establishFigure(G);break;
case 2:establishTrain(G,T,trainPath,tmPath);break;
case 3:establishPlane(G,H,planePath,pmPath);break;
case 4:
trainFloyd(G,tmPath,tPath,tmDisk);
printTFloyd(G,tPath,tmDisk);break;
};
}while(i!=6);
}
//建立全国交通图
void establishFigure(ALGraph * G)
{
int i;
do
{
cout<
cin>>i;
switch(i)
{
case 1:estFigure(G);break;
case 2:estffile(G);break;
case 3:addCity(G);break;
case 4:deleteCity(G);break;
case 5:break;
default:cout<<" 错误选择!!!请重选";
}
}while(i!=5);
}
//文件输入建立全国交通图
void estffile(ALGraph * &G)
{
int v,k,i,j;
cout<<" *****************************************************************************************"<
EdgeNode * s;
in_stream>>G->n>>G->e;
for(v=0;v
{
in_stream>>G->adjlist[v].vertex;
G->adjlist[v].firstedge=NULL;
}
for(k=0;k in_stream>>T->Train[i-1].firstBusTime.minutes; createTrainPathMatrix(T,trainPath,tmPath,traStation,j,i); } //文件输入建立航空时刻表 //建立火车时刻表 void estPlane(ALGraph * G,planelist * H,int ** planePath,int ** pmPath) void initializeTrainPathMatrix(ALGraph * G,int ** trainPath,int ** tmPath) void createPlanePathMatrix(planelist * H,int ** planePath,int ** pmPath,int * plaStation,int num,int k) void printPlanePathMatrix(ALGraph * G,int ** planePath,int ** pmPath,int * plaStation) int i,j=0,v;
{
in_stream>>i;
in_stream>>j;
s=(EdgeNode *)malloc(sizeof(EdgeNode));
s->adjvex=j;
s->next=G->adjlist[i-1].firstedge;
G->adjlist[i-1].firstedge=s;
in_stream>>G->adjlist[i-1].firstedge->eInfo;
s=(EdgeNode *)malloc(sizeof(EdgeNode));
s->adjvex=i;
s->next=G->adjlist[j-1].firstedge;
G->adjlist[j-1].firstedge=s;
G->adjlist[j-1].firstedge->eInfo=G->adjlist[i-1].firstedge->eInfo;
}
in_stream.close();
cout<<" 建立的全国交通图的邻接表为:"<
{
EdgeNode * q=G->adjlist[i].firstedge;
cout<<" "<
while(q!=NULL)
{
cout<
cout<<"("<
cout<<"->";
q=q->next;
}
cout<<"NULL"<
cout<
}
//文件输入建立火车时刻表
void estffileTrain(ALGraph * G,trainlist * & T,int ** trainPath,int ** tmPath)
{
int i,j,v;
int traStation[MaxVerNum];
cout<<" *****************************************************************************************"<
train * s,* R;
in_stream>>T->m;
initializeTrainPathMatrix(G,trainPath,tmPath);
for(i=1;i<=T->m;i++)
{
in_stream>>j;
for(v=1;v<=j;v++)
{
in_stream>>traStation[v-1];
}
in_stream>>T->Train[i-1].divisions;
in_stream>>T->Train[i-1].firstBusTime.hours;
in_stream>>T->Train[i-1].firstBusTime.synbol;
s=(train *)malloc(sizeof(train));
s->trainName=traStation[0];
in_stream>>s->time;
in_stream>>s->money;
in_stream>>s->stopTime;
s->nextStation=NULL;
T->trainSchedule[i-1].trainRoute=s;
R=s;
for(v=2;v
s=(train *)malloc(sizeof(train));
s->trainName=traStation[v-1];
in_stream>>s->time;
in_stream>>s->money;
in_stream>>s->stopTime;
s->nextStation=NULL;
R->nextStation=s;
R=s;
}
s=(train *)malloc(sizeof(train));
s->trainName=traStation[j-1];
s->time=0;
s->distance=0;
s->money=0;
s->stopTime=0;
s->nextStation=NULL;
R->nextStation=s;
R=s;
train * q;
cout<<" 分别输出构建好的每一条路线:"<
{
q=T->trainSchedule[i-1].trainRoute;
cout<<" ";
while(q)
{
cout<
q=q->nextStation;
}
cout<
in_stream.close();
cout<
}
void estffilePlane(ALGraph * G,planelist * & H,int ** planePath,int ** pmPath)
{
cout<<" *****************************************************************************************"<
int i,j,v;
int plaStation[MaxVerNum];
plane * s,* R;
in_stream>>H->x;
cout<
for(i=1;i<=H->x;i++)
{
in_stream>>j;
for(v=1;v<=j;v++)
{
in_stream>>plaStation[v-1];
}
in_stream>>H->Plane[i-1].divisions;
in_stream>>H->Plane[i-1].firstBusTime.hours;
in_stream>>H->Plane[i-1].firstBusTime.synbol;
in_stream>>H->Plane[i-1].firstBusTime.minutes;
s=(plane *)malloc(sizeof(plane));
s->planeName=plaStation[0];
in_stream>>s->platime;
in_stream>>s->plamoney;
in_stream>>s->plastoptime;
s->planextStation=NULL;
H->planeSchedule[i-1].planeRoute=s;
R=s;
for(v=2;v
s=(plane *)malloc(sizeof(plane));
s->planeName=plaStation[v-1];
in_stream>>s->platime;
in_stream>>s->plamoney;
in_stream>>s->plastoptime;
s->planextStation=NULL;
R->planextStation=s;
R=s;
}
s=(plane *)malloc(sizeof(plane));
s->planeName=plaStation[j-1];
s->platime=0;
s->pladistance=0;
s->plamoney=0;
s->plastoptime=0;
s->planextStation=NULL;
R->planextStation=s;
R=s;
createPlanePathMatrix(H,planePath,pmPath,plaStation,j,i);
}
in_stream.close();
plane * q;
cout<<" 分别输出构建好的每一条路线:"<
{
q=H->planeSchedule[i-1].planeRoute;
cout<<" ";
while(q)
{
cout<
q=q->planextStation;
}
cout<
cout<
}
void establishTrain(ALGraph * G,trainlist * T,int ** trainPath,int ** tmPath)
{
int i;
do
{
cout<
cin>>i;
switch(i)
{
case 1:estTrain(G,T,trainPath,tmPath);break;
case 2:estffileTrain(G,T,trainPath,tmPath);break;
case 3:addTrainPath(G,T,trainPath,tmPath);break;
case 4:deleteTrainPath(G,T,trainPath,tmPath);break;
case 5:break;
default:cout<<" 错误选择!!!请重选";
}
}while(i!=5);
}
//建立航空时刻表
void establishPlane(ALGraph * G,planelist * H,int ** planePath,int ** pmPath)
{
int i;
do
{
cout<
cin>>i;
switch(i)
{
case 1:estPlane(G,H,planePath,pmPath);break;
case 2:estffilePlane(G,H,planePath,pmPath);break;
case 3:addPlanePath(G,H,planePath,pmPath);break;
case 4:deletePlanePath(G,H,planePath,pmPath);break;
case 5:break;
default:cout<<" 错误选择!!!请重选";
}
}while(i!=5);
}
void estFigure(ALGraph * G)
{
cout<<" *****************************************************************************************"<
cout<
cout<
void estTrain(ALGraph * G,trainlist * T,int ** trainPath,int ** tmPath)
{
cout<<" *****************************************************************************************"<
cout<
cout<
{
cout<<" *****************************************************************************************"<
cout<
cout<
void create(ALGraph * & G)
{
int v,k,i,j;
EdgeNode * s;
cout<<" 请输入城市数和城市之间连通的路径数:";
cin>>G->n>>G->e;
cout<<" 请输入各城市名称并以回车终止输入:"<
{
cout<<" ";
cin>>G->adjlist[v].vertex;
new_line();
G->adjlist[v].firstedge=NULL;
}
cout<<" 所有城市名称及对应序号为:"<
for(v=0;v
{
cout<
cout<<"->"<
cout<
{
cout<<" 读入(vi-vj)的城市的对应序号"<
cin>>i;
cin>>j;
s=(EdgeNode *)malloc(sizeof(EdgeNode));
s->adjvex=j;
s->next=G->adjlist[i-1].firstedge;
G->adjlist[i-1].firstedge=s;
cout<<" "<<"输入"< cin>>G->adjlist[i-1].firstedge->eInfo;
s=(EdgeNode *)malloc(sizeof(EdgeNode));
s->adjvex=i;
s->next=G->adjlist[j-1].firstedge;
G->adjlist[j-1].firstedge=s;
G->adjlist[j-1].firstedge->eInfo=G->adjlist[i-1].firstedge->eInfo;
}
}
void printA(ALGraph * G)
{
int i;
cout<<" 建立的全国交通图的邻接表为:"<
{
EdgeNode * q=G->adjlist[i].firstedge;
cout<<" "<
while(q!=NULL)
{
cout<
cout<<"("<
cout<<"->";
q=q->next;
}
cout<<"NULL"<
}
void new_line()
{
char symbol;
do
{
cin.get(symbol);
}while(symbol!='\n');
}
void createTrainSchedule(ALGraph * G,trainlist * & T,int ** trainPath,int ** tmPath)
{
int i,j,v;
int traStation[MaxVerNum];
train * s,* R;
EdgeNode * p;
cout<<" 请输入您所需要建立的列车路线总数:";
cin>>T->m;
cout<
for(i=1;i<=T->m;i++)
{
cout<<" 开始创建第"< cout<<" 请输入第"< cin>>j;
cout<<" 请按顺序输入每一站城市名称对应的序号:";
for(v=1;v<=j;v++)
{
cin>>traStation[v-1];
}
cout<
cout<<" 请输入首班车出发的时间:";
cin>>T->Train[i-1].firstBusTime.hours;
cin>>T->Train[i-1].firstBusTime.synbol;
cin>>T->Train[i-1].firstBusTime.minutes;
if(T->Train[i-1].firstBusTime.hours<0||T->Train[i-1].firstBusTime.hours>=24||T->Train[i-1].firstBusTime.synbol!=':'||T->Train[i-1].firstBusTime.minutes<0||T->Train[i-1].firstBusTime.minutes>=60)
{
do
{
cout<<" 时间输入有误,请重新输入"<
cin>>T->Train[i-1].firstBusTime.hours;
cin>>T->Train[i-1].firstBusTime.synbol;
cin>>T->Train[i-1].firstBusTime.minutes;
}while(T->Train[i-1].firstBusTime.hours<0||T->Train[i-1].firstBusTime.hours>=24||T->Train[i-1].firstBusTime.synbol!=':'||T->Train[i-1].firstBusTime.minutes<0||T->Train[i-1].firstBusTime.minutes>=60);
}
cout<
s->trainName=traStation[0];
cout<<" 请输入到达下一站所需要的时间:";
cin>>s->time;
cout<<" 到达下一站的路程为:";
p=G->adjlist[(s->trainName)-1].firstedge;
while(p->adjvex!=traStation[1])
p=p->next;
cout<
cin>>s->money;
cout<<" 请输入到达下一站后停靠的时间:";
cin>>s->stopTime;
s->nextStation=NULL;
T->trainSchedule[i-1].trainRoute=s;
R=s;
for(v=2;v
cout<
s->trainName=traStation[v-1];
cout<<" 请输入到达下一站所需要的时间:";
cin>>s->time;
cout<<" 到达下一站的路程为:";
p=G->adjlist[(s->trainName)-1].firstedge;
while(p->adjvex!=traStation[v])
p=p->next;
cout<
cin>>s->money;
cout<<" 请输入到达下一站后停靠的时间:";
cin>>s->stopTime;
s->nextStation=NULL;
R->nextStation=s;
R=s;
}
s=(train *)malloc(sizeof(train));
s->trainName=traStation[j-1];
s->time=0;
s->distance=0;
s->money=0;
s->stopTime=0;
s->nextStation=NULL;
R->nextStation=s;
R=s;
cout<
}
//printTrainPathMatrix(G,trainPath,tmPath,traStation);
}
void printTrain(ALGraph * G,trainlist * T)
{
int i;
train * p;
cout<<" 分别输出构建好的每一条路线:"<
{
p=T->trainSchedule[i-1].trainRoute;
cout<<" ";
while(p)
{
cout<
p=p->nextStation;
}
cout<
}
void createplaneSchedule(ALGraph * G,planelist * & H,int ** planePath,int ** pmPath)
{
int i,j,v;
int plaStation[MaxVerNum];
plane * s,* R;
EdgeNode * p;
cout<<" 输入您所需要建立的航空路线总数:";
cin>>H->x;
cout<
for(i=1;i<=H->x;i++)
{
cout<<" 开始创建第"< cout<<" 请输入第"< cin>>j;
cout<<" 请按顺序输入每一站城市名称对应的序号:";
for(v=1;v<=j;v++)
{
cin>>plaStation[v-1];
}
cout<
cout<<" 请输入首班车出发的时间:";
cin>>H->Plane[i-1].firstBusTime.hours;
cin>>H->Plane[i-1].firstBusTime.synbol;
cin>>H->Plane[i-1].firstBusTime.minutes;
if(H->Plane[i-1].firstBusTime.hours<0||H->Plane[i-1].firstBusTime.hours>=24||H->Plane[i-1].firstBusTime.synbol!=':'||H->Plane[i-1].firstBusTime.minutes<0||H->Plane[i-1].firstBusTime.minutes>=60)
{
do
{
cout<<" 时间输入有误,请重新输入"<
cin>>H->Plane[i-1].firstBusTime.hours;
cin>>H->Plane[i-1].firstBusTime.synbol;
cin>>H->Plane[i-1].firstBusTime.minutes;
}while(H->Plane[i-1].firstBusTime.hours<0||H->Plane[i-1].firstBusTime.hours>=24||H->Plane[i-1].firstBusTime.synbol!=':'||H->Plane[i-1].firstBusTime.minutes<0||H->Plane[i-1].firstBusTime.minutes>=60);
}
cout<
s->planeName=plaStation[0];
cout<<" 请输入到达下一站所需要的时间:";
cin>>s->platime;
cout<<" 到达下一站的路程为:";
p=G->adjlist[(s->planeName)-1].firstedge;
while(p->adjvex!=plaStation[1])
p=p->next;
cout<
cin>>s->plamoney;
cout<<" 请输入到达下一站后停靠的时间:";
cin>>s->plastoptime;
s->planextStation=NULL;
H->planeSchedule[i-1].planeRoute=s;
R=s;
for(v=2;v
cout<
s->planeName=plaStation[v-1];
cout<<" 请输入到达下一站所需要的时间:";
cin>>s->platime;
cout<<" 到达下一站的路程为:";
p=G->adjlist[(s->planeName)-1].firstedge;
while(p->adjvex!=plaStation[v])
p=p->next;
cout<
cin>>s->plamoney;
cout<<" 请输入到达下一站后停靠的时间:";
cin>>s->plastoptime;
s->planextStation=NULL;
R->planextStation=s;
R=s;
}
s=(plane *)malloc(sizeof(plane));
s->planeName=plaStation[j-1];
s->platime=0;
s->pladistance=0;
s->plamoney=0;
s->plastoptime=0;
s->planextStation=NULL;
R->planextStation=s;
R=s;
cout<
}
printPlanePathMatrix(G,planePath,pmPath,plaStation);
}
void printplane(ALGraph * G,planelist * H)
{
int i;
plane * p;
cout<<" 分别输出构建好的每一条路线:"<
{
p=H->planeSchedule[i-1].planeRoute;
cout<<" ";
while(p)
{
cout<
p=p->planextStation;
}
cout<
}
void printTime(ALGraph * G,trainlist * T)
{
int i;
for(i=1;i<=T->m;i++)
{
if(T->Train[i-1].firstBusTime.hours<10)
cout<<"0";
cout<
if(T->Train[i-1].firstBusTime.minutes<10)
cout<<"0";
cout<
}
void initializePlanePathMatrix(ALGraph * G,int ** planePath,int ** pmPath)
{
int i,j;
for(i=0;i
for(j=0;j
planePath[i][j]=0;
for(i=0;i
for(j=0;j
pmPath[i][j]=0;
}
{
int i,j;
for(i=0;i
for(j=0;j
trainPath[i][j]=0;
for(i=0;i
for(j=0;j
tmPath[i][j]=0;
}
void createTrainPathMatrix(trainlist * T,int ** trainPath,int ** tmPath,int * traStation,int num,int k)
{
int i,j,v;
train * p=T->trainSchedule[k-1].trainRoute;
for(v=1;v
i=traStation[v-1]-1;
j=traStation[v]-1;
trainPath[i][j]=1;
trainPath[j][i]=1;
tmPath[i][j]=p->money;
tmPath[j][i]=p->money;
p=p->nextStation;
}
}
{
int i,j,v;
plane * p=H->planeSchedule[k-1].planeRoute;
for(v=1;v
i=plaStation[v-1]-1;
j=plaStation[v]-1;
planePath[i][j]=1;
planePath[j][i]=1;
pmPath[i][j]=p->plamoney;
pmPath[j][i]=p->plamoney;
p=p->planextStation;
}
}
void printTrainPathMatrix(ALGraph * G,int ** trainPath,int ** tmPath,int * traStation)
{
int i,j;
for(i=1;i<=G->n;i++)
{
for(j=1;j<=G->n;j++)
cout<
cout<
{
for(j=1;j<=G->n;j++)
cout<
}
{
int i,j;
for(i=1;i<=G->n;i++)
{
for(j=1;j<=G->n;j++)
cout<
cout<
{
for(j=1;j<=G->n;j++)
cout<
}
void addCity(ALGraph * &G)
{
cout<
EdgeNode * s;
cout<<" 请输入你所需要添加的城市的名称:";
cin>>G->adjlist[G->n].vertex;
new_line();
G->adjlist[G->n].firstedge=NULL;
cout<<" 请输入该城市共与多少城市相连:";
cin>>j;
(G->n)+=1;
cout<
for(v=0;v
{
cout<
cout<<"->"<
cout<
for(i=1;i<=j;i++)
{
cin>>ver[i-1];
}
for(i=1;i<=j;i++)
{
s=(EdgeNode *)malloc(sizeof(EdgeNode));
s->adjvex=ver[i-1];
s->next=G->adjlist[(G->n)-1].firstedge;
G->adjlist[(G->n)-1].firstedge=s;
cout<<" "<<"输入"<
s=(EdgeNode *)malloc(sizeof(EdgeNode));
s->adjvex=G->n;
s->next=G->adjlist[ver[i-1]-1].firstedge;
G->adjlist[ver[i-1]-1].firstedge=s;
G->adjlist[ver[i-1]-1].firstedge->eInfo=G->adjlist[(G->n)-1].firstedge->eInfo;
}
cout<
cout<
void deleteCity(ALGraph * &G)
{
cout<<" ";
for(v=0;v
{
cout<
cout<<"->"<
cout<
cin>>v;
new_line();
if(v<0||v>G->n)
{
cout<<" 你想要删除的城市不存在!!!"<
}
EdgeNode * p=G->adjlist[v-1].firstedge;
while(p->next)
{
EdgeNode * s=p->next;
p->next=s->next;
free (s);
}
G->adjlist[v-1].firstedge=p->next;
free (p);
for(i=1;i<=G->n;i++)
{
EdgeNode * p=G->adjlist[i-1].firstedge;
if(p)
{
if(p->next==NULL)
{
if(p->adjvex==v)
{
G->adjlist[i-1].firstedge=p->next;
free (p);
continue;
}
}
else
{
if(p->adjvex==v)
{
G->adjlist[i-1].firstedge=p->next;
free (p);
continue;
}
else
{
while(p->next)
{
EdgeNode * s=p->next;
if(s->adjvex==v)
{
p->next=s->next;
free (s);
break;
}
else
p=p->next;
}
}
}
}
}
for(i=v-1;i
{
G->adjlist[i]=G->adjlist[i+1];
}
(G->n)-=1;
for(j=v+1;j<=(G->n)+1;j++)
{
for(i=1;i<=G->n;i++)
{
EdgeNode * p=G->adjlist[i-1].firstedge;
while(p)
{
if(p->adjvex==j)
{
(p->adjvex)-=1;
break;
}
else
p=p->next;
}
}
}
printA(G);
}
void addTrainPath(ALGraph * G,trainlist * & T,int ** trainPath,int ** tmPath)
{
cout<
train * s,* R;
EdgeNode * p;
cout<<" 当前添加的为第"<
T->m+=1;
T->trainSchedule[T->m-1].trainRoute=NULL;
cout<<" 开始创建第"<
cout<<" 请输入第"<
cin>>j;
cout<
for(v=0;v
{
cout<
cout<<"->"<
cout<
for(v=1;v<=j;v++)
{
cin>>traStation[v-1];
}
cout<
cin>>T->Train[T->m-1].divisions;
cout<<" 请输入首班车出发的时间:";
cin>>T->Train[T->m-1].firstBusTime.hours;
cin>>T->Train[T->m-1].firstBusTime.synbol;
cin>>T->Train[T->m-1].firstBusTime.minutes;
if(T->Train[T->m-1].firstBusTime.hours<0||T->Train[T->m-1].firstBusTime.hours>=24||T->Train[T->m-1].firstBusTime.synbol!=':'||T->Train[T->m-1].firstBusTime.minutes<0||T->Train[T->m-1].firstBusTime.minutes>=60)
{
do
{
cout<<" 时间输入有误,请重新输入"<
cin>>T->Train[T->m-1].firstBusTime.hours;
cin>>T->Train[T->m-1].firstBusTime.synbol;
cin>>T->Train[T->m-1].firstBusTime.minutes;
}while(T->Train[T->m-1].firstBusTime.hours<0||T->Train[T->m-1].firstBusTime.hours>=24||T->Train[T->m-1].firstBusTime.synbol!=':'||T->Train[T->m-1].firstBusTime.minutes<0||T->Train[T->m-1].firstBusTime.minutes>=60);
}
cout<
cout<<" 请输入第1站"<
s->trainName=traStation[0];
cout<<" 请输入到达下一站所需要的时间:";
cin>>s->time;
cout<<" 到达下一站的路程为:";
p=G->adjlist[(s->trainName)-1].firstedge;
while(p->adjvex!=traStation[1])
p=p->next;
cout<
cin>>s->money;
cout<<" 请输入到达下一站后停靠的时间:";
cin>>s->stopTime;
s->nextStation=NULL;
T->trainSchedule[T->m-1].trainRoute=s;
R=s;
for(v=2;v
cout<
s->trainName=traStation[v-1];
cout<<" 请输入到达下一站所需要的时间:";
cin>>s->time;
cout<<" 到达下一站的路程为:";
p=G->adjlist[(s->trainName)-1].firstedge;
while(p->adjvex!=traStation[v])
p=p->next;
cout<
cin>>s->money;
cout<<" 请输入到达下一站后停靠的时间:";
cin>>s->stopTime;
s->nextStation=NULL;
R->nextStation=s;
R=s;
}
s=(train *)malloc(sizeof(train));
s->trainName=traStation[j-1];
s->time=0;
s->distance=0;
s->money=0;
s->stopTime=0;
s->nextStation=NULL;
R->nextStation=s;
R=s;
cout<
printTrain(G,T);
}
void deleteTrainPath(ALGraph * G,trainlist * & T,int ** trainPath,int ** tmPath)
{
cout<
train * p,* s;
printTrain(G,T);
cout<
cin>>j;
if(j<0||j>T->m)
{
cout<<" 你想要删除的城市不存在!!!"<
}
p=T->trainSchedule[j-1].trainRoute;
while(p->nextStation)
{
s=p->nextStation;
p->nextStation=s->nextStation;
free (s);
}
T->trainSchedule[j-1].trainRoute=p->nextStation;
free (p);
for(i=j;i
{
T->trainSchedule[i-1]=T->trainSchedule[i];
}
T->m-=1;
/*for(i=1;i<=T->m+1;i++)
initializeTrainPathMatrix(G,trainPath,tmPath);
for(i=1;i<=T->m;i++)
createTrainPathMatrix(T,trainPath,tmPath,traStation,j,T->m);
printTrainPathMatrix(G,trainPath,tmPath,traStation);*/
printTrain(G,T);
}
void addPlanePath(ALGraph * G,planelist * & H,int ** planePath,int ** pmPath)
{
cout<
plane * s,* R;
EdgeNode * p;
cout<<" 当前添加的为第"<
H->x+=1;
H->planeSchedule[H->x].planeRoute=NULL;
cout<<" 开始创建第"<
cout<<" 请输入第"<
cin>>j;
cout<
for(v=0;v
{
cout<
cout<<"->"<
cout<
for(v=1;v<=j;v++)
{
cin>>plaStation[v-1];
}
cout<
cin>>H->Plane[H->x-1].divisions;
cout<<" 请输入首班车出发的时间:";
cin>>H->Plane[H->x-1].firstBusTime.hours;
cin>>H->Plane[H->x-1].firstBusTime.synbol;
cin>>H->Plane[H->x-1].firstBusTime.minutes;
if(H->Plane[H->x-1].firstBusTime.hours<0||H->Plane[H->x-1].firstBusTime.hours>=24||H->Plane[H->x-1].firstBusTime.synbol!=':'||H->Plane[H->x-1].firstBusTime.minutes<0||H->Plane[H->x-1].firstBusTime.minutes>=60)
{
do
{
cout<<" 时间输入有误,请重新输入"<
cin>>H->Plane[H->x-1].firstBusTime.hours;
cin>>H->Plane[H->x-1].firstBusTime.synbol;
cin>>H->Plane[H->x-1].firstBusTime.minutes;
}while(H->Plane[H->x-1].firstBusTime.hours<0||H->Plane[H->x-1].firstBusTime.hours>=24||H->Plane[H->x-1].firstBusTime.synbol!=':'||H->Plane[H->x-1].firstBusTime.minutes<0||H->Plane[H->x-1].firstBusTime.minutes>=60);
}
cout<
cout<<" 请输入第1站"<
s->planeName=plaStation[0];
cout<<" 请输入到达下一站所需要的时间:";
cin>>s->platime;
cout<<" 到达下一站的路程为:";
p=G->adjlist[(s->planeName)-1].firstedge;
while(p->adjvex!=plaStation[1])
p=p->next;
cout<
cin>>s->plamoney;
cout<<" 请输入到达下一站后停靠的时间:";
cin>>s->plastoptime;
s->planextStation=NULL;
H->planeSchedule[H->x-1].planeRoute=s;
R=s;
for(v=2;v
cout<
s->planeName=plaStation[v-1];
cout<<" 请输入到达下一站所需要的时间:";
cin>>s->platime;
cout<<" 到达下一站的路程为:";
p=G->adjlist[(s->planeName)-1].firstedge;
while(p->adjvex!=plaStation[v])
p=p->next;
cout<
cin>>s->plamoney;
cout<<" 请输入到达下一站后停靠的时间:";
cin>>s->plastoptime;
s->planextStation=NULL;
R->planextStation=s;
R=s;
}
s=(plane *)malloc(sizeof(plane));
s->planeName=plaStation[j-1];
s->platime=0;
s->pladistance=0;
s->plamoney=0;
s->plastoptime=0;
s->planextStation=NULL;
R->planextStation=s;
R=s;
cout<
printPlane(G,H);
}
void deletePlanePath(ALGraph * G,planelist * & H,int ** planePath,int ** pmPath)
{
cout<
plane * p,* s;
printPlane(G,H);
cout<
cin>>j;
if(j<0||j>H->x)
{
cout<<" 你想要删除的城市不存在!!!"<
}
p=H->planeSchedule[j-1].planeRoute;
while(p->planextStation)
{
s=p->planextStation;
p->planextStation=s->planextStation;
free (s);
}
H->planeSchedule[j-1].planeRoute=p->planextStation;
free (p);
for(i=j;i
{
H->planeSchedule[i-1]=H->planeSchedule[i];
}
H->x-=1;
/*for(i=1;i<=T->m+1;i++)
initializeTrainPathMatrix(G,trainPath,tmPath);
for(i=1;i<=T->m;i++)
createTrainPathMatrix(T,trainPath,tmPath,traStation,j,T->m);
printTrainPathMatrix(G,trainPath,tmPath,traStation);*/
printPlane(G,H);
}
void printPlane(ALGraph * G,planelist * H)
{
int i;
plane * p;
cout<<" 分别输出构建好的每一条路线:"<
{
p=H->planeSchedule[i-1].planeRoute;
cout<<" ";
while(p)
{
cout<
p=p->planextStation;
}
cout<
}
void trainFloyd(ALGraph * G,int ** tmPath,int ** tPath,int ** tmDisk)
{
int i,j,k;
for(i=0;i
{
for(j=0;j
{
tmDisk[i][j]=tmPath[i][j];
if(i!=j&&tmPath[i][j]
else
tPath[i][j]=-1;
}
}
for(k=0;k
{
for(i=0;i
{
for(j=0;j
{
if(i!=j&&tmDisk[i][j]>tmDisk[i][k]+tmDisk[k][j])
{
tmDisk[i][j]=tmDisk[i][k]+tmDisk[k][j];
tPath[i][j]=tPath[k][j];
}
}
}
}
}
void printTFloyd(ALGraph * G,int ** tPath,int ** tmDisk)
{
int k,x,i,j;
sNode * top;
for(i=0;i
{
for(j=0;j
{
if(i!=j)
{
cout<"<
cout<<"不存在路径";
else
{
cout<<"最少需付费"<
do
{
k=tPath[i][k];
initialStack(top);
pushStack(top,k);
}while(k!=i);
do
{
popStack(top,x);
cout<
}
}
}
}
}
void initialStack(sNode * & top)
{
top=NULL;
}
void pushStack(sNode * & top,int x)
{
sNode * s;
s=new sNode;
s->data=x;
s->inext=top;
top=s;
}
void popStack(sNode * & top,int &x)
{
sNode * u;
if(top==NULL)
return;
else
{
x=top->data;
u=top;
top=top->inext;
delete u;
}
}