您的位置:首页 > 理论基础 > 数据结构算法

再回首,数据结构——树的常用术语、树和二叉树的存储结构

2015-05-28 11:22 344 查看
       最近在复习数据结构,顺便看看大一的时候写的代码,看完之后比当初有了更加深刻的体会。

       希望这些能提供给初学者一些参考。

//树的常用术语
/*
<span style="font-size:24px;"> 1.结点(Node)
2.度(Degree)
3.树的度
4.叶子(Leaf)
5.分支结点
6.孩子和双亲(Child & Parent)
7.兄弟(Sibling) 祖先和子孙(Ancestor & Descendant)
8.结点的层次(Level)
9.堂兄弟
10.树的深度(Depth)</span>
*/

//树的存储结构
//1.双亲(数组)表示法
#define MaxSize 50
typedef struct
{
ElementType data;
int parent;
}SeqTrNode;

typedef struct
{
SeqTrNode tree[Maxsize];
int nodenum;
}SeqTree;

SeqTree T;

//2.孩子表示法
#define MaxSize 50
typedef struct ChNode //孩子链表的结点类型
{
int child;
struct ChNode *next;
}ChildNode, *ChPoint;

typedef struct /*顺序表中每个结点的类型*/
{
ElementType data;
ChPoint FirstChild; //指向第一个孩子节点的指针
}Node;

typedef struct //树的类型
{
Node TreeList[MaxSize];
int nodenumber; //树中实际所含结点的个数
}Chlist;

//3.孩子兄弟表示法
typedef struct TrNode //树中每个结点的类型
{
ElementType data;
struct TrNode *FirstChild, *RigthSibling;
}TreeNode, *ChSiTree;
ChSiTree root; //指向树根结点的指针

//二叉树的存储结构

//1.顺序存储
#define MaxSize 30
typedef struct SeqBT
{
char btree[MaxSize];
int length; //二叉树中所含结点的实际个数
}SeqBT;

//2.链式存储
typedef struct BNode
{
ElementType data;
struct BNode *lchild;
struct BNode *rchild;
}BTNode;
typedef BTNode* BinTree;

//3.三叉链表
typedef struct BPNode
{
ElementType data;
struct BPNode *lchild;
struct BPNode *rchild;
struct BPNode *parent;
}BTPNode, *BTPTree;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据结构
相关文章推荐