#include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int status;
typedef int ElemType;
typedef int bool;
#define true 1
#define false 0
//邻接矩阵
#define MaxInt 32767
#define MVNum 100
typedef char VerTexType;
typedef int ArcType;
typedef struct
{
VerTexType vexs[MVNum];
ArcType arcs[MVNum][MVNum];
int vexnum,arcnum;
}AMGraph;
int LocateVex_AM(AMGraph G,VerTexType v)
{
int i=0;
//while(i<G.vexnum&&v!=G.vexs[i])
//i++;
for(;i<G.vexnum;i++)
if(G.vexs[i]==v)
break;
return i;
}
status CreateUDN_AM(AMGraph *G,VerTexType *V)
{
int i,j,k;
for(i=0;i<G->vexnum;i++)
G->vexs[i]=V[i];
for(i=0;i<G->vexnum;i++)
for(j=0;j<G->vexnum;j++)
G->arcs[i][j]=MaxInt;
char v1,v2;
for(k=0;k<G->arcnum;k++)
{
scanf("%c%c",&v1,&v2);
getchar();//吃回车!!
int i=LocateVex_AM(*G,v1);
int j=LocateVex_AM(*G,v2);
G->arcs[i][j]=1
数据结构C语言-图的建立以及深度优先、广度优先遍历
最新推荐文章于 2023-12-27 15:33:17 发布
本文详细介绍了如何使用C语言构建图的数据结构,并实现了深度优先搜索和广度优先搜索的遍历算法。通过具体的代码展示了这两种遍历方法在图操作中的应用。
摘要由CSDN通过智能技术生成