树的存储和图的存储结构总结
【摘要】
目录标题
树图
#define max_size 100
1
树
//双亲表示法
struct Node{
int data;
int parent;//记录父节点再数组的位置
}...
#define max_size 100
- 1
树
//双亲表示法
struct Node{
int data;
int parent;//记录父节点再数组的位置
};
struct Tree {
Node TreeArr[max_size];
int n;//节点数
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
//孩子表示法
struct childNode {
int childIndex;
childNode* nextChild;
};
struct firstChild {
int data;
childNode* FChild;
};
struct Tree {
firstChild nodes[max_size];
int n;//节点数
int root;//根的位置
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
//孩子兄弟表示法
struct ChildBrotherNode {
int data;
ChildBrotherNode* firstChild;
ChildBrotherNode* nextBrother;
};
- 1
- 2
- 3
- 4
- 5
- 6
图
/*
graph的存储结构
*/
//邻接矩阵法
struct graph {
char vex[max_size];//定点表
int edge[max_size][max_size];
int vernum;//顶点个数和弧的个数
int arcnum;
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
//邻接表法
struct ArcNode {//弧
int adjvex;//所指向的定点
ArcNode* next;//下一条弧
};
struct HNode {//顶点
int data;
ArcNode* firstArc;//指向第一个弧
};
struct graph {
HNode* vertices[max_size];
int vernum;
int arcnum;//弧的个数
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
//十字链表法
struct ArcNode {
int info;
int tailvex;//用来存储尾号
int headvex;//用来存储弧头
ArcNode* hlink;//弧头相同的下一条弧
ArcNode* tlink;//弧尾相同的下一条弧
};
struct VerNode{
int data;
ArcNode* headArc;//指向该节点作为弧头的第一条弧
ArcNode* tailArc;//指向该节点作为弧尾的第一条弧
};
struct graphList {
VerNode* VerList[max_size];
int vernum;//顶点的个数
int arcnum;//弧的个数
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
//邻接多重表
struct ArcNode {
int i;//i和j表示两个链接的点的位置
int j;
int info;
ArcNode* iLink;
ArcNode* jLink;
};
struct verNode
{
int data;
ArcNode* fistEdge;
};
struct graphList {
verNode* gList[max_size];
int vernum;
int arcnum;
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
文章来源: blog.csdn.net,作者:肥学,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jiahuiandxuehui/article/details/124658590
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)