徐州网站推广优化排名优化公司
一、图
二、程序 (与十字链表差不多)
/*
项目名称:邻接多重表存储无向图
编译环境:VC++ 2008
作者相关:。。。
最后修改:2019.10.30
学习目标:1.掌握邻接多重表存储无图的基本操作
注意事项:1.测试所有功能是否正常遇到问题:*/#include <stdio.h>
#include <stdlib.h>#define MAX_VERTEX_NUM 20
#define ERROR 0
#define OK 1typedef bool Status;
typedef char VertexType;
typedef char InfoType;
typedef enum{unvisited,visited} VisitIf;typedef struct ArcNode
{VisitIf mark;//访问标记int ivex,jvex;//该边依附的两个顶点的位置struct ArcNode *ilink,*jlink;//分别指向依附着两个顶点的下一条边InfoType *info;//该边的信息
}ArcNode;typedef struct VexNode
{VertexType data;ArcNode *firstarc;//指向第一条依附该项点的边
}VexNode;typedef struct
{VexNode vexs[MAX_VERTEX_NUM];int vexnum,arcnum;//无向图的当前顶点数和边数
}AMLGraph;Status CreateAMLGraph(AMLGraph &G);int GetIndex(AMLGraph G,VertexType v);int main()
{AMLGraph G;CreateAMLGraph(G);return 0;
}Status CreateAMLGraph(AMLGraph &G)
{int IncInfo,i,j,index1,index2;VertexType v1,v2;ArcNode *p;printf("请输入无向图的顶点数和边数:\n");scanf("%d%d",&G.vexnum,&G.arcnum);printf("\n");for(i=0;i<G.vexnum;i++)//构造顶点数组{printf("请输入第%d个顶点\n",i+1);fflush(stdin);scanf("%c",&G.vexs[i].data);G.vexs[i].firstarc=NULL;}printf("\n");for(j=0;j<G.arcnum;j++){printf("请输入第%d条边依附的两个顶点:\n",j+1);fflush(stdin);scanf("%c,%c",&v1,&v2);index1=GetIndex(G,v1);index2=GetIndex(G,v2);p=(ArcNode *)malloc(sizeof(ArcNode));p->mark=unvisited;p->ivex=index1;p->jvex=index2;p->ilink=G.vexs[index1].firstarc;p->jlink=G.vexs[index2].firstarc;p->info=NULL;G.vexs[index1].firstarc=p;G.vexs[index2].firstarc=p;}return OK;}//获得顶点v在G中的下标
int GetIndex(AMLGraph G,VertexType v)
{int i;for(i=0;i<G.vexnum;i++)if(G.vexs[i].data==v)return i;if(i==G.vexnum)return -1;
}