鱼C论坛

 找回密码
 立即注册
查看: 3766|回复: 4

创建邻接矩阵问题

[复制链接]
发表于 2014-3-4 23:22:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
# 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[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)
{
        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[i]);
        }
        for(i=0;i<g.vexnum;i++)
                for(j=0;j<g.vexnum;j++)
                {
                        g.arc[i][j]=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[m][n]=w;
                g.arc[n][m]=g.arc[m][n];

        }
        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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-3-5 08:57:33 | 显示全部楼层
不明觉厉,帮顶
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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最后结束有问题,懒得找了,这错误还真不少
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-3-27 15:49:05 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-8-15 13:27:49 | 显示全部楼层
回帖是一种美德
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-6 03:00

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表