哪里出错了,运行不了啊,后天就要交了,帮帮忙啊
#include<stdio.h>#include<string.h>
#define MAX_VERTEX_NUM 10
#define INFINITY 1000
#define FALSE 0
#define TRUE 1
typedef struct ArCell
{
int Length;
}ArCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
typedef struct
{
char name[30];
int num;
char introduction[100];
}infotype;
typedef struct
{
infotype vexs[MAX_VERTEX_NUM];
AdjMatrix arcs;
int vexnum,arcnum;
}MGraph;
void ShortestPath_DIJ(MGraph *G)
{
int v,w,i,min,t=0,x,flag=1,v0;
int final[20],D[20],p[20][20];
while(flag)
{
printf("请输入要查询的景点编号:");
scanf("%d",&v0);
if(v0<0||v0>G->vexnum)
{
printf("景点编号不存在!请重新输入景点编号:");
scanf("%d",&v0);
}
if(v0>=0&&v0<G->vexnum)
flag=0;
}
for(v=0;v<G->vexnum;v++)
{
final[v]=0;
D[v]=G->arcs[v0][v].Length;
for(w=0;w<G->vexnum;w++)
p[v][w]=0;
if(D[v]<INFINITY)
{
p[v][v0]=1;
p[v][v]=1;
}
}
D[v0]=0;
final[v0]=1;
for(i=1;i<G->vexnum;i++)
{
min=INFINITY;
for(w=0;w<G->vexnum;w++)
if(!final[w])
if(D[w]<min)
{
v=w;
min=D[w];
}
final[v]=1;
for(w=0;w<G->vexnum;w++)
if(!final[w]&&(min+G->arcs[v][w].Length<D[w]))
{
D[w]=min+G->arcs[v][w].Length;
for(x=0;x<G->arcnum;x++)
p[w][x]=p[v][x];
p[w][w]=1;
}
}
for(v=0;v<G->vexnum;v++)
{
if(v0!=v)
printf("%s",G->vexs[v0].name);
for(w=0;w<G->vexnum;w++)
{
if(p[v][w]&&w!=v0)
printf("-->%s",G->vexs[w].name);
t++;
}
if(t>G->vexnum-1&&v0!=v)
printf(" 总路线长%dm\n\n",D[v]);
}
}
void Floyd(MGraph *G)
{
int v,u,i,w,k,j,flag=1,p[10][10][10],D[10][10];
for(v=0;v<G->vexnum;v++)
for(w=0;w<G->vexnum;w++)
{
D[v][w]=G->arcs[v][w].Length;
for(u=0;u<G->vexnum;u++)
p[v][w][u]=0;
if(D[v][w]<INFINITY)
{
p[v][w][v]=1;
p[v][w][w]=1;
}
}
for(u=0;u<G->vexnum;u++)
for(v=0;v<G->vexnum;v++)
for(w-0;w<G->vexnum;w++)
{
D[v][w]=D[v][u]+D[u][w];
for(i=0;i<G->vexnum;i++)
p[v][w][i]=p[v][u][i]||p[u][w][i];
}
while(flag)
{
printf("请输入出发点和目的地的编号:");
scanf("%d%d",&k,&j);
if(k<0||k>G->vexnum||j<0||j>G->vexnum)
{
printf("景点编号不存在!请重新输入出发点和目的地的编号:");
scanf("%d%d",&k,&j);
}
if(k>=0&&k<G->vexnum&&j>=0&&j<G->vexnum)
flag=0;
}
printf("%s",G->vexs[k].name);
for(u=0;u<G->vexnum;u++)
if(p[k][j][u]&&k!=u&&j!=u)
printf("->%s",G->vexs[u].name);
printf("->%s",G->vexs[j].name);
printf("总路线长%dm\n",D[k][j]);
}
void Search(MGraph *G)
{
int k,flag=1;
while(flag)
{
printf("请输入要查询的景点编号:");
scanf("%d",&k);
if(k<0||k>G->vexnum)
{
printf("景点编号不存在!请重新输入景点编号:");
scanf("%d",&k);
}
if(k>=0&&k<G->vexnum)
flag=0;
}
printf("*编号*景点名称 *简介*\n");
printf("*%-4d*%-16s*%-56s\n",G->vexs[k].num,G->vexs[k].name,G->vexs[k].introduction);
}
main()
{
int i,j;
char c;
MGraph *G;
strcpy(G->vexs[0].name,"浙江工商大学北门");
strcpy(G->vexs[0].introduction,"学校正门朴素而不华丽,彰显学校的诚毅勤朴。\n");
strcpy(G->vexs[1].name,"浙江工商大学行政楼");
strcpy(G->vexs[1].introduction,"坐落在学校正门前,采用月牙形的设计,凸显学校的庄严与主体建筑的控制。\n");
strcpy(G->vexs[2].name,"浙江工商大学图书馆");
strcpy(G->vexs[2].introduction,"共有楼,分为自习室,电子阅览室,普通阅览室,需刷卡进入,保证了学生能唯一享受学校的资源。\n");
strcpy(G->vexs[3].name,"浙江工商大学现教中心");
strcpy(G->vexs[3].introduction,"安排机房,方便学生进行资料查询和考试练习。\n");
strcpy(G->vexs[4].name,"浙江工商大学教学楼") ;
strcpy(G->vexs[4].introduction,"共有A,B,C,D,E,F六幢教学楼,并且都配备空调,多媒体,教室充足。\n");
strcpy(G->vexs[5].name,"浙江工商大学体育馆");
strcpy(G->vexs[5].introduction,"众多的体育设施能充分满足浙江工商大学学生的训练,健身需求。\n");
strcpy(G->vexs[6].name,"浙江工商大学操场");
strcpy(G->vexs[6].introduction,"总共有三个操场,让学生们有足够的活动空间。\n");
strcpy(G->vexs[7].name,"浙江工商大学学生活动中心");
strcpy(G->vexs[7].introduction,"具有多个学生活动的场所,丰富学生的课余活动。\n");
strcpy(G->vexs[8].name,"浙江工商大学金沙港生活区");
strcpy(G->vexs[8].introduction,"只有少部分的学生入住,环境清幽,自带独立阳台和卫生间。\n");
strcpy(G->vexs[9].name,"浙江工商大学钱江湾生活区");
strcpy(G->vexs[9].introduction,"靠近钱塘江,园内绿草如茵,环境优雅,寝室设备齐全。\n");
for(i=0;i<10;i++)
for(j=0;j<10;j++)
G->arcs[i][j].Length=INFINITY;
G->arcs[0][1].Length=60;
G->arcs[0][2].Length=70;
G->arcs[0][3].Length=90;
G->arcs[0][7].Length=50;
G->arcs[0][8].Length=1000;
G->arcs[0][9].Length=60;
G->arcs[1][2].Length=30;
G->arcs[1][7].Length=70;
G->arcs[1][6].Length=60;
G->arcs[2][3].Length=20;
G->arcs[3][4].Length=20;
G->arcs[3][9].Length=30;
G->arcs[5][6].Length=40;
G->arcs[6][7].Length=70;
G->arcs[6][8].Length=500;
G->arcs[8][9].Length=900;
G->arcs[1][0].Length=60;
G->arcs[2][0].Length=70;
G->arcs[3][0].Length=90;
G->arcs[7][0].Length=50;
G->arcs[8][0].Length=1000;
G->arcs[9][0].Length=60;
G->arcs[2][1].Length=30;
G->arcs[7][1].Length=70;
G->arcs[6][1].Length=60;
G->arcs[3][2].Length=20;
G->arcs[4][3].Length=20;
G->arcs[9][3].Length=30;
G->arcs[6][5].Length=40;
G->arcs[7][6].Length=70;
G->arcs[8][6].Length=500;
G->arcs[9][8].Length=900;
printf("1.景点信息查询:\n");
printf("2.景点路径查询:\n");
printf("3.最短路径查询:\n");
printf("4.退出\n");
scanf("%c",&c);
switch(c)
{
case'1':Search(G);break;
case'2':ShortestPath_DIJ(G);break;
case'3':Floyd(G);break;
case'4':printf("欢迎您的到来,谢谢!\n");break;
}
}