关于昨天的句子:高分问题,大家过来看看这个floyd算法的源代码

来源:百度文库 编辑:高考问答 时间:2024/05/02 18:33:56
刚开始学C++,同时也在学数据结构,对于floyd算法有个疑问,下面这些代码有问题吗?怎么我测试不了呢?请高手卡看看,帮忙测试一下,可以的话也把测试的数据和结果也给出来参考参考,或者发到我的邮箱laohaomail@126.com,谢谢了!!必定以高分回报

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define INFINITY 9999
#define FALSE 0
#define TRUE 1
#define M_vexnum 50
#define M_arcnum 50

struct Graph{
int vexnum;
double arcx[M_vexnum][M_arcnum];
};

void Short_Path(Graph G)
{
int v,w,i,u;
double sum[M_vexnum];
double D[M_vexnum][M_vexnum];
int P[M_vexnum][M_vexnum][M_vexnum];

for(v=0;v<G.vexnum;v++)
for(w=0;w<G.vexnum;w++){
D[v][w]=G.arcx[v][w];
for(u=0;u<G.vexnum;u++)
P[v][w][u]=FALSE;
if(D[v][w]<INFINITY)
{P[v][w][u]=TRUE;P[v][w][w]=TRUE;}
}
for(u=0;u<G.vexnum;u++)
for(v=0;v<G.vexnum;v++)
for(w=0;w<G.vexnum;w++)
if(D[v][u]+D[u][w]<D[v][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];
}
for(v=0;v<G.vexnum;v++)
{
sum[v]=0;
for(w=0;w<G.vexnum;w++)
{
sum[v]+=D[v][w];
cout<<D[v][w]<<" "; }
cout<<endl;
}
for(i=0;i<G.vexnum;i++)
cout<<sum[i]<<" ";
cout<<endl;
}

void main()
{
Graph G;
G.vexnum=12;
double a,b;
cout<<"Please INput the num:";
cin>>a>>b;
for(int i=0;i<G.vexnum;i++)
for(int j=0;j<G.vexnum;j++)
if(i==j)G.arcx[i][j]=0;
else G.arcx[i][j]=INFINITY;
G.arcx[0][1]=G.arcx[1][0]=a; G.arcx[0][5]=G.arcx[5][0]=a;
G.arcx[1][2]=G.arcx[2][1]=a; G.arcx[1][6]=G.arcx[6][1]=a;
G.arcx[2][7]=G.arcx[7][2]=a;
G.arcx[3][4]=G.arcx[4][3]=b;G.arcx[3][9]=G.arcx[9][3]=sqrt(5)*a;
G.arcx[3][11]=G.arcx[11][3]=a;
G.arcx[4][5]=G.arcx[5][4]=b;
G.arcx[5][6]=G.arcx[6][5]=b;
G.arcx[6][7]=G.arcx[7][6]=b;
G.arcx[7][8]=G.arcx[8][7]=b;
G.arcx[9][10]=G.arcx[10][9]=a;
G.arcx[10][11]=G.arcx[11][10]=a;
Short_Path(G);
}

我没有编译过去你的程序
估计是Graph结构有问题吧

struct Graph{
int vexnum;
double arcx[M_vexnum][M_arcnum];
}
错误信息,下面的,我使用linux编译的
你看看你的结构是不是有问题,你编这个东西干嘛,好乱啊,没必要吧?
呵呵,别的我也搞不清楚了
能帮你的只有这么多,我也是个新手
test.c: In function `Short_Path':
test.c:24: `G' undeclared (first use in this function)
test.c:24: (Each undeclared identifier is reported only once
test.c:24: for each function it appears in.)
test.c:47: `cout' undeclared (first use in this function)
test.c:48: `endl' undeclared (first use in this function)
test.c: In function `main':
test.c:57: `Graph' undeclared (first use in this function)
test.c:57: syntax error before "G"
test.c:58: `G' undeclared (first use in this function)
test.c:60: `cout' undeclared (first use in this function)
test.c:61: `cin' undeclared (first use in this function)
test.c:62: `for' loop initial declaration used outside C99 mode
test.c:63: `for' loop initial declaration used outside C99 mode
test.c:56: warning: return type of `main' is not `int'