主题:<求助>谁帮我改下错误
题目:
4.城市最短路径问题
【问题描述】
A、B、C、D、E五城市分别距离为( 单位是: km):
A - B 300 A – E 3000 B - C 2500
B - D 800 C – E 1000 D - A 2000
D - C 400 D - E 1200 E – A 500
现从未地出发,到其它各城市的最捷路径。 输出各条最捷路径
#define MAXVEX 10
#define NULL-1
#define A 0
#define B 1
#define C 2
#define D 3
#define E 4
typedef int Vertex;
typedef Vertex elemtype;
typedef char VexType;
typedef int AdjType;
int visited[MAXVEX];
typedef struct
{ Vextype vexs[MAXVEX]; /*顶点信息*/
Adjtypearcs[MAXVEX][MAXVEX];/*边信息*/
int n; /*图的顶点个数*/
}GrahMatrix;
void dijkstra(GraphMatrix g,Vertex v)
{int dist[MAXVEX];
Vertex closevex[MAXVEX],path[MAXVEX];
int i,j=1,k,min,l;
for(i=0;i<g.n;i++)
{closevex[l]=0;
dist[i]=g.arcs[v][i];
path[i]=v;
}
closevex[v]=1;
while(j<g.n)
{min=9999;
for(l=0;l<g.n:l++)
if(closevex[l]==0 && min>dist[l])
{dist[l]>dist[k]+g.arcs[k][l])
path[l]=k;
/*closevex[l]*/
}
j++;
}
for(l=0;l<g.n;l++)
printf("(V%d,V%d,V%d),%d,",v,path[l],l,dist[l]);
}
main()
{ GraphMatrix g={{'A','B','C','D','E'},
{{0,300,9999,9999,3000},
{9999,0,2500,800,9999},
{9999,0,2500,800,9999},
{9999,9999,0,9999,1000},
{2000,9999,400,0,1200},
{500,9999,9999,9999,0}}
,5};
printf("FromA(V0)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,0);
printf("FromB(V1)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,1);
printf("FromC(V2)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,2);
printf("FromD(V3)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,3);
printf("FromE(V4)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,4);
getch();
}
运行后显示
错误 noname.c 14 :说明缺少 ':'
错误 noname.c 18 :变量列表语法错误
急急急
4.城市最短路径问题
【问题描述】
A、B、C、D、E五城市分别距离为( 单位是: km):
A - B 300 A – E 3000 B - C 2500
B - D 800 C – E 1000 D - A 2000
D - C 400 D - E 1200 E – A 500
现从未地出发,到其它各城市的最捷路径。 输出各条最捷路径
#define MAXVEX 10
#define NULL-1
#define A 0
#define B 1
#define C 2
#define D 3
#define E 4
typedef int Vertex;
typedef Vertex elemtype;
typedef char VexType;
typedef int AdjType;
int visited[MAXVEX];
typedef struct
{ Vextype vexs[MAXVEX]; /*顶点信息*/
Adjtypearcs[MAXVEX][MAXVEX];/*边信息*/
int n; /*图的顶点个数*/
}GrahMatrix;
void dijkstra(GraphMatrix g,Vertex v)
{int dist[MAXVEX];
Vertex closevex[MAXVEX],path[MAXVEX];
int i,j=1,k,min,l;
for(i=0;i<g.n;i++)
{closevex[l]=0;
dist[i]=g.arcs[v][i];
path[i]=v;
}
closevex[v]=1;
while(j<g.n)
{min=9999;
for(l=0;l<g.n:l++)
if(closevex[l]==0 && min>dist[l])
{dist[l]>dist[k]+g.arcs[k][l])
path[l]=k;
/*closevex[l]*/
}
j++;
}
for(l=0;l<g.n;l++)
printf("(V%d,V%d,V%d),%d,",v,path[l],l,dist[l]);
}
main()
{ GraphMatrix g={{'A','B','C','D','E'},
{{0,300,9999,9999,3000},
{9999,0,2500,800,9999},
{9999,0,2500,800,9999},
{9999,9999,0,9999,1000},
{2000,9999,400,0,1200},
{500,9999,9999,9999,0}}
,5};
printf("FromA(V0)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,0);
printf("FromB(V1)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,1);
printf("FromC(V2)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,2);
printf("FromD(V3)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,3);
printf("FromE(V4)toA(V0)B(V1)C(V2)D(V3)E(V4)shortest round is:\n");
dijkstra(g,4);
getch();
}
运行后显示
错误 noname.c 14 :说明缺少 ':'
错误 noname.c 18 :变量列表语法错误
急急急