| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1837 人关注过本帖
标题:DG DN UDG怎么做
取消只看楼主 加入收藏
yf879326915
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2017-4-12
收藏
 问题点数:0 回复次数:0 
DG DN UDG怎么做
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define INFINITY INT_MAX
#define MAX_VERTEX_NUM 20
typedef int Status;
typedef int VRType;
typedef int InfoType;
typedef enum {DG,DN,UDG,UDN} GraphKind;
typedef struct ArcCell {
    VRType adj;
    InfoType *info;
}ArcCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
typedef char VertexType;
typedef struct {
    VertexType vexs[MAX_VERTEX_NUM];
    AdjMatrix arcs;
    int vexnum,arcnum;
    GraphKind kind;
}MGraph;

int LocateVex(MGraph G,char v){
    int i;
    for(i=0;i<G.vexnum;++i)
        if(G.vexs[i]==v) return i;
        return -1;
}

Status CreateUDN(MGraph &G){
    int i,j,k,w;
    VertexType v1,v2;
    printf("输入顶点数G.vexnum:"); scanf("%d",&G.vexnum);
    printf("输入边数G.arcnum:"); scanf("%d",&G.arcnum);
    getchar();
    for(i=0;i<G.vexnum;i++){
        printf("输入顶点G.vex[%d]:",i);
        scanf("%c",&G.vexs[i]);
        getchar();
    }
    for(i=0;i<G.vexnum;++i)
        for(j=0;j<G.vexnum;++j){
            G.arcs[i][j].adj=INFINITY;
            G.arcs[i][j].info=NULL;
        }
        for(k=0;k<G.arcnum;++k){
            printf("输入第%d条边vi,vj和权值w(int):\n",k+1);
            scanf("%c %c %d",&v1,&v2,&w);
            getchar();
            i=LocateVex(G,v1); j=LocateVex(G,v2);
            G.arcs[i][j].adj=w;
            G.arcs[j][i].adj=G.arcs[i][j].adj;
        }
        return OK;
}

Status CreateGraph(MGraph &G){
    printf("请输入图的种类: 0表示DG,1表示Dn,2表示UDG,3表示UDN\n");
    scanf("%d",&G.kind);
    switch(G.kind){
      //  case  DG:return CreateDG(G);
     //   case  DN:return CreateDN(G);
      //  case UDG:return CreateUDG(G);
        case UDN:return CreateUDN(G);
        default:return ERROR;
    }
}

void list(MGraph G){
    int i,j;
    printf("输入邻接矩阵:\n");
    for(i=0;i<G.vexnum;++i){
        printf("%c----",G.vexs[i]);
        for(j=0;j<G.vexnum;++j)
            if(G.arcs[i][j].adj==INFINITY)
                printf("%4d","∞");
            else
                printf("%4d",G.arcs[i][j].adj);
            printf("\n");
    }
}

void main() {
    MGraph G;
    CreateGraph(G);
    list(G);
}

搜索更多相关主题的帖子: include 
2017-05-05 21:46
快速回复:DG DN UDG怎么做
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055255 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved