创建邻接矩阵问题
# include <stdio.h>
# include <stdlib.h>
#define MAXVEX 20
#define NON -1
typedef char VexType;
typedef float AdjType;
typedef int Status;
typedef struct
{
int vexnum,arcnum;
VexType vex;
AdjType arc;
}GraphMatrix;
int LocateVex(GraphMatrix *pgraph, VexType v)
{
int k;
for (k=0;k<pgraph->vexnum;k++)
if(v==pgraph->vex) return k;
return NON;
}
Status CreateUDN((GraphMatrix &g)
{
Adjtype w;
VexType v1,v2;
int i,j,m,n;
printf("input the vexnum:"); scanf("%d",&g.vexnum);
printf("input the arcnum:"); scanf("%d",&g.arcnum);
for(i=0;i<g.vexnum;i++)
{
printf("input the vex[%d]:",i);
scanf("%c",&g.vex);
}
for(i=0;i<g.vexnum;i++)
for(j=0;j<g.vexnum;j++)
{
g.arc=INFINITY;
}
for(j=0;j<g.arcnum;j++)
{
printf("input v1:");scanf("%c",&v1);
printf("input v2:");scanf("%c",&v2);
printf("input w:"); scanf("%d",&w);
m=LocateVex(&g,v1);
n=LocateVex(&g,v2);
g.arc=w;
g.arc=g.arc;
}
return OK;
}
main()
{
GraphMatrix g;
CreateUDN(&g);
}
出现这些错误,求大神!
D:\Users\narutoxyl\新建文件夹 (2)\邻接矩阵.c(48) : error C2143: syntax error : missing ')' before '('
D:\Users\narutoxyl\新建文件夹 (2)\邻接矩阵.c(48) : error C2143: syntax error : missing ')' before '&'
D:\Users\narutoxyl\新建文件夹 (2)\邻接矩阵.c(48) : error C2091: function returns function
D:\Users\narutoxyl\新建文件夹 (2)\邻接矩阵.c(48) : error C2143: syntax error : missing '{' before '&'
D:\Users\narutoxyl\新建文件夹 (2)\邻接矩阵.c(48) : error C2059: syntax error : '&'
D:\Users\narutoxyl\新建文件夹 (2)\邻接矩阵.c(48) : error C2059: syntax error : ')'
D:\Users\narutoxyl\新建文件夹 (2)\邻接矩阵.c(84) : warning C4013: 'CreateUDN' undefined; assuming extern returning int 不明觉厉,帮顶 # include <stdio.h>
# include <stdlib.h>
#define MAXVEX 20
#define NON -1
#define INFINITY 65535
typedef char VexType;
typedef float AdjType;
typedef int Status;
typedef struct
{
int vexnum,arcnum;
VexType vex;
AdjType arc;
}GraphMatrix;
int LocateVex(GraphMatrix *pgraph, VexType v)
{
int k;
for (k=0;k<pgraph->vexnum;k++)
if(v==pgraph->vex) return k;
return NON;
}
Status CreateUDN(GraphMatrix *g)//c语言没有这样用&g,那是c++
{
AdjType w;//大小写
VexType v1,v2,temp= 0;//作用见下面
int i,j,m,n;
printf("input the vexnum:");
scanf("%d",&g->vexnum);
printf("input the arcnum:");
scanf("%d",&g->arcnum);
gets(&temp);//接受上次回车字符,可以去掉看看效果
for(i=0;i<g->vexnum;i++)
{
printf("input the vex[%d]:",i);
gets(&g->vex);
// scanf("%c",&(g->vex));回车也算字符
}
for(i=0;i<g->vexnum;i++)
for(j=0;j<g->vexnum;j++)
{
g->arc=INFINITY;//#define INFINITY 65535
}
for(j=0;j<g->arcnum;j++)
{
printf("input v1:");
gets(&v1);
//scanf("%c",&v1);
printf("input v2:");
gets(&v2);
//scanf("%c",&v2);
printf("input w:");
scanf("%d",&w);
m=LocateVex(g,v1);
n=LocateVex(g,v2);
g->arc=w;
g->arc=g->arc;
gets(&temp);//接受上次回车字符,可以去掉看看效果
}
return 1;
}
int main()
{
GraphMatrix g;
CreateUDN(&g);
return 0;
}
改完,vc6.0通过,vs2010最后结束有问题,懒得找了,这错误还真不少
九方卧虫 发表于 2014-3-21 10:25 static/image/common/back.gif
# include
# include
感谢大神! 回帖是一种美德
页:
[1]