用 迪杰斯克特拉算法 求最短路径
#include <stdio.h>
#include <stdlib.h>
#define INF 9999
const int MAXVEX= 99999;
void main()
{
int cost[6][MAXVEX]={
{0, INF, 100, 30, INF, 10},
{INF, 0, INF, INF, INF, 5},
{INF, INF, 0, INF, INF,INF},
{INF, INF, 60, 0, 20, INF},
{INF, INF, 10, INF, 0, INF},
{INF, INF, INF, INF, 50, 0}};
Dijkstra (cost, 6, 1);
printf("\n");
system("pause");
return 0;
}
void Dijkstra (int cost[][MAXVEX],int n, int v)
{
int dist[MAXVEX], path[MAXVEX];
int s[MAXVEX];
int mindis, i, j, u, pre;
for (i=0; i<n; i++)
{ dist[i]=cost[v][i];
s[i]=0;
if (cost[v][i]<INF)
path[i]=v;
else
path[i]=-1;
}
s[v]=1;path[v]=0;
for (i=0; i<n; i++)
{ mindis=INF;
u=-1;
for (j=0; j<n; j++)
if (s[j]==0 && dist[j]<mindis)
{
u=j;
mindis=dist[j];
}
if (u!=-1)
{ s[u]=1;
for (j=0; j<n; j++)
if (s[j]==0)
if (cost[u][j]<INF && dist[u]+cost[u][j]<dist[j])
{ dist[j]=dist[u]+cost[u][j];
path[j]=u;
}
}
}
printf("\n The methods of Dijkstra are as follow:\n");
for (i=0;i<n;i++)
{
if (i!=v)
{ printf("vi:");
if (s[i]==1)
{ printf ("The length of the path is:" ,dist[i]);
pre=i;
printf ("The reversed path is:");
while (pre!=v)
{ printf("pre");
pre=path[pre];
}
printf("pre");
}
else
printf("The path dose not exist!");
}
}
}
用 迪杰斯克特拉算法 求最短路径
大家帮忙看下,在 Dev—cpp 下运行总报错!!