//编译环境 Visual Studio 2008 win32 console application
//MGragh.c
////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#define MaxVertexNum 100//最大顶点数
#define QM 100 //队列的最大元素个数
#define OK 1
#define ERROR 0
int visited[MaxVertexNum];
typedef enum{DG,DN,NDG,NDN}GraphKind;//图的种类,有向图,有向网,无向图,无向网
typedef int VertexType;//顶点类型
typedef struct
{
int adj;//相邻与否,或权值大小
}ArcCell;
typedef struct
{
VertexType vexs[MaxVertexNum];//顶点表
ArcCell arcs[MaxVertexNum][MaxVertexNum];//邻接矩阵,边表
int vexnum,arcnum;//图中当前的顶点数和边数
int Graphkind;//图的种类标志
}MGragh;
////////////////////////////////////////////定义队列,用于广度优先遍历//////////////////////////////////////
typedef struct
{
VertexType *base;
VertexType front,rear;
}SQueue;
/////////////////////////////////////////函数声明///////////////////////////////////////////////////////////
int LocateVex(MGragh *M,VertexType v);
int CreateDN(MGragh *M);//有向网,带权值
int CreateDG(MGragh *M);//有向图,无权值
int CreateUDN(MGragh *M);//无向网,带权值
int CreateUDG(MGragh *M);//无向图,带权值
int CreatGragh(MGragh *G);
int FirstAdjVex(MGragh *G,int v);//返回V的第一个邻接顶点
int NextAdjVex(MGragh *G,int v,int w);//返回V的相对于W的下一个邻接顶点
void BFSTraverse(MGragh *G);//广度遍历
void DFS(MGragh *G,int v0);
void DFSTaverse(MGragh *G);//深度遍历
void PrintMatrix(MGragh *G);
void InsertVex(MGragh *G,int v);
int DeVex(MGragh *G,VertexType v);
int InserArc(MGragh *G);
int DeArc(MGragh *G);
///////////////////与队列有关的声明/////////////////////////////////
void InitQueue(SQueue *Q);
void EnQueue(SQueue *Q,int e);
int QueueEmpty(SQueue *Q);
void DeQueue(SQueue *Q,int*e);
///////////////////////////////////////主函数/////////////////////////////////////////////////////////
void main()
{
MGrag
数据结构的C实现_图_邻接矩阵表示
最新推荐文章于 2024-02-17 00:37:04 发布
本文介绍了如何使用C语言实现数据结构中的图,特别是邻接矩阵表示法。通过创建不同类型的图(有向图、无向图、有向网、无向网),进行广度优先遍历、深度优先遍历,并提供了插入顶点、删除顶点、添加弧和删除弧的功能。代码示例展示了具体的操作过程。

最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



