图的邻接矩阵存储

来源:互联网 发布:mac忘记admin密码 编辑:程序博客网 时间:2024/05/17 08:25
//图的邻接矩阵表示法/*#include <iostream>using namespace std;struct graph{char vexs[100];//图中顶点的数组int arc[100][100];//图的邻接矩阵int numvertexes,numedges;//顶点数和边数}g;void creategraph(graph *g){int i,j,k;cin>>g->numvertexes>>g->numedges;for(i=0;i<g->numvertexes;i++)//输入顶点数组{g->vexs[i]=getchar();}for(i=0;i<g->numedges;i++)//初始化邻接矩阵for(j=0;j<g->numedges;j++)cin>>g->arc[i][j];}*///邻接链表表示法#include <iostream>using namespace std;const int max_vex=30;typedef enum{dg,ag,wdg,wag}graphkind;struct linknode//边节点类型定义{int adjvex;//邻接点(于vi连通的其它节点)在头结点数组中的位置下标int info;//边或弧的信息,这里表示权值linknode *nextarc;//指向下一个表节点};struct vexnode//顶点结点定义类型{char data;//顶点信息,这里用char型表示          //typedef char vextype;使用模板表示linknode *firstarc;//指向第一个表节点};struct algraph//图的结构定义{graphkind kind;//图的种类标志int vexnum;vexnode adjlist[max_vex];//表头向量}

0 0
原创粉丝点击