现在有如下所示的图:

来源:百度知道 编辑:UC知道 时间:2024/05/24 22:41:49
请分别写出利用邻接矩阵或邻接表存储该图,并按照深度优先遍历该图中所有顶点的C程序。
这是作业
希望做过的同学把你的代码让我参考参考
是使用C写的代码

代码发到你邮箱了~~
我不太希望我的代码随便放到网上

参考一下吧!

#include <iostream.h>
#include <stdlib.h>

#define INFINITY 0

#define MAX_VERTEX_NUM 10 //最大顶点数

#define MAX_EDGE_NUM 40 //最大边数

typedef enum {DG,DN,UDG,UDN}Graphkind;

typedef char VertexType; //顶点数据类型

typedef struct ArcCell
{
int adj; //无权图,1或0表示相邻否;带权图则是权值。
//int *info;
}ArcCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];

typedef struct
{
VertexType vexs[MAX_VERTEX_NUM]; //顶点向量
AdjMatrix arcs; //邻接矩阵
int vexnum,arcnum; //图的当前顶点数和弧数。
Graphkind kind;
}MGraph;

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

int CreatUDN(MGraph &G)
// 采用数组表示法,构造无向网 G
{
VertexType v1,v2;
int w,j;
cout<<"输入图的顶点数"<