|
发表于 2014-3-21 10:25:17
|
显示全部楼层
# 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[MAXVEX];
AdjType arc[MAXVEX][MAXVEX];
}GraphMatrix;
int LocateVex(GraphMatrix *pgraph, VexType v)
{
int k;
for (k=0;k<pgraph->vexnum;k++)
if(v==pgraph->vex[k]) 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[i]);
// scanf("%c",&(g->vex[i]));回车也算字符
}
for(i=0;i<g->vexnum;i++)
for(j=0;j<g->vexnum;j++)
{
g->arc[i][j]=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[m][n]=w;
g->arc[n][m]=g->arc[m][n];
gets(&temp);//接受上次回车字符,可以去掉看看效果
}
return 1;
}
int main()
{
GraphMatrix g;
CreateUDN(&g);
return 0;
}
改完,vc6.0通过,vs2010最后结束有问题,懒得找了,这错误还真不少
|
|