Type storage structure
Sequential storage structure
description
This structure is a set of contiguous memory locations (such as arrays) binary data storage nodes, parent-child relationship between nodes through which they are to reflect the relative position without the need for any additional memory cells to store a pointer.
Objects
Typically complete binary tree for storage.
Feature
Starting at the root of the number of, from top to bottom, left to right, one to the node numbers and the data stored in the corresponding cell in an array.
step
To sum up, the complete binary tree of N nodes, for the subscript i node:
1. When the i / 2 (rounding)> = time. 1, i / 2 (rounding) unit is a parent node; when the I / 2 (rounding) = 0, root node indicates that the node number, no parent node.
2. When 2i when <= N, 2i when its left child unit; otherwise, no left child.
3. When 2i +. 1 <when N =, 2i +. 1 when its right child unit; otherwise no right child.
4. Array unit starting index is 1 .
advantage
Storage space utilization is high, the calculation is simple.
Shortcoming
Not easy to achieve add, delete operation.
Binary Tree chain store
typedef struct TNode *Position;
typedef Position BinTree; //二叉树类型
struct TNode //数结点定义
{
ElementType Data; //结点数据
BinTree Left; //指向左子树
BinTree Right; //指向右子树
};
Wherein, Data pointer field indicates the value of the number of nodes, point to point session left child root node domain representation of the Left, Right are pointers to the right child of the root node. The following figure is an example, a binary tree concerning, b is represented achieve its list.