数据结构之---C语言实现图的数组(邻接矩阵)存储表示

//图的数组(邻接矩阵)存储表示
#include 
#include 
#define MAX_VEX_NUM 50
typedef char VertexType;
typedef enum {
    DG, UDG
} GraphType;
typedef struct {
    VertexType vexs[MAX_VEX_NUM];
    int arcs[MAX_VEX_NUM][MAX_VEX_NUM];
    int vexnum, arcnum;
    GraphType type;
} MGraph;
 
//定位
int getIndexOfVexs(char vex, MGraph *MG)
{
    int i;
    for (i = 1; i <= MG->vexnum; i++) 
	{
        if (MG->vexs[i] == vex) 
		{
            return i;
        }
    }
    return 0;
}
 
//创建图
void create_MG(MGraph *MG) 
{
    int i, j, k;
    int v1, v2, type;
    char c1, c2;
    printf("Please input graph type DG(0) or UDG(1) :");
    scanf("%d", &type);
    if (type == 0)
        MG->type = DG;
    else if (type == 1)
        MG->type = UDG;
    else 
	{
        printf("Please input correct graph type DG(0) or UDG(1)!");
        return;
    }
 
    printf("Please input vexmun : ");
    scanf("%d", &MG->vexnum);
    prin

你可能感兴趣的:(C,&&,C++,数据结构,算法)