栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

数据结构基础-图

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

数据结构基础-图

  • 图的概念
  • 图的表达
  • 图的存储结构
  • 图的基本操作

图的存储结构 邻接矩阵法

更适应于稠密图

#include
using namespace std;

#define maxVertexnum 100
typedef char VertexType;
typedef int EdgeType;
typedef struct{
	VertexType Vex[maxVertexnum];
	EdgeType Edge[maxVertexnum][maxVertexnum];
	int vexnum,arcnum;
}Graph;

//有向图 
void create(Graph &g){
	int vex = 4,arc = 4;
	g.arcnum=arc;
	g.vexnum = vex;
	for(int i = 0;ig.vexnum || y>g.vexnum) return false;
	if(g.Edge[x][y] >= 1) return true;
}
void Neighbors(Graph g,int x){ //print x's neighbors vertex
	for(int i=0;i= 1){
			cout<= 1){
			cout<= 1){
		g.Edge[x][y] = 0;
	}
}
int main(){
	Graph g = new Graph();
	create(g);
}
邻接表法

更适应于稀疏图

#include
using namespace std;
#define maxVertexnum 100
typedef char VertexType

typedef struct ArcNode{
	int adjvex;
	struct ArcNode *next;
}ArcNode;
typedef struct VNode{
	VertexType data;
	ArcNode *first;
}VNode,AdjList[maxVertexnum];
typedef struct{
	AdjList vertices;
	int vexnum,arcnum;
}Graph;

void ADjacent(G,x,y);//is have edge x-y
void Neighbors(G,x); //print x's neighbors vertex
void InsertVertex(G,x);// insert x
void DeleteVertex(G,x);// delete x
void AddEdge(G,x,y); // add edge for x-y
void RemoveEdge(G,x,y);// remove the edge of x-y
十字链表法

有向图的一种链式表示

#include
#define maxVextexTypeNum 100
typedef char VertexType;
typedef int EdgeType;
using namespace std;
typedef struct ArcNode{
	int tailvex,headvex;	//尾域和头域 
	struct ArcNode *hlink,*tlink;	//出单链表和入单链表
	//Infotype info; 
}ArcNode;
typedef struct Vnode{
	VertexType data;
	ArcNode *firstin,*firstout;
}Vnode;
typedef struct{
	Vnode list[maxVertexTypeNum];
	int vexnum,arcnum;
}ALGraph;
int main(){
	
} 
邻接多重表

无向图的一种链式表示

#include
#define maxVextexTypeNum 100
typedef char VertexType;
typedef int EdgeType;
using namespace std;
typedef struct ArcNode{
	int mark;
	int ivex,jvex;
	ArcNode *ilink,*jlink;
	//InfoType info;
}ArcNode;
typedef struct Vnode{
	VertexType data;
	ArcNode *firstedge;
}Vnode;
typedef struct{
	Vnode list[maxVertexTypeNum];
	int vexnum,arcnum;
}ALGraph;

内容链接
绪论上一篇博客
线性表上一篇博客:线性表
栈和队列上一篇博客:栈和队列
树和二叉树上一篇博客:树与二叉树
正在翻阅此文章
查找下一篇博客:查找
排序下一篇博客:排序
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/298074.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号