//树的链式存储--双亲表示法 #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX_TREE_SIZE 100 typedef struct BPTNode { char data;//数据域 int parentPosition; //双亲的数组下标 char LRTag; //左右孩子标志域 }BPTNode; typedef struct BPTree { BPTNode nodes[100]; //因为节点之间是分散的,需要把节点存储到数组中 int num_node; //节点数目 int root; //根结点的位置 //注意此域存储的是父亲节点在数组的下标 }BPTree; void Test1(){ BPTNode t1, t2, t3, t4, t5,t6; BPTree bt; bt.nodes[0] = t1; bt.nodes[1] = t2; bt.nodes[2] = t3; bt.nodes[3] = t4; bt.nodes[4] = t5; bt.nodes[5] = t6; bt.num_node = 6; bt.root = 0; t1.data = 'A'; t1.LRTag = '0'; t1.parentPosition = '-1'; t1.data = 'B'; t1.LRTag = '0'; t1.parentPosition = '0'; t1.data = 'C'; t1.LRTag = '1'; t1.parentPosition = '0'; t1.data = 'D'; t1.LRTag = '0'; t1.parentPosition = '1'; t1.data = 'E'; t1.LRTag = '1'; t1.parentPosition = '1'; t1.data = 'F'; t1.LRTag = '1'; t1.parentPosition = '2'; } void main(){ system("pause"); }
数据结构 树的链式存储(双亲表示法)
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:数据结构 树的遍历(递归遍历)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【数据结构】二叉树的存储结构
【数据结构】第五章——树与二叉树详细介绍二叉树的存储结构……
二叉树 数据结构 C语言 -
【数据结构】链式家族的成员——循环链表与静态链表
【数据结构】第二章——线性表(8)详细介绍了循环链表与静态链表的相关内容……
数据结构 C语言 循环链表 静态链表 -
数据结构 树的表示,存储结构与遍历
查找的概念:根据某个
结点 子树 二叉树 -
树的三种表示法:双亲表示法、孩子表示法、孩子兄弟表示法
大佬博客传送门
结点 链表 数据 -
【数据结构笔记17】集合的表示、双亲表示法、并查集、集合的并运算
使用双亲表示法表示一个集合。
集合的表示 双亲表示法 并查集 并运算 结点