Chained storage structure
The chain storage structure of binary tree means that a binary tree is represented by a chain list, that is, the logical relation of the element is indicated by the chain.
The usual method is that each node in the list consists of three fields, the data field and the left and right pointer fields, and the left hand pointer is used to give the storage address of the node where the child and the child are located. Its node structure is:
Where the data domain holds information about a node, lchild and Rchild each hold a pointer to the left child and right child, and when the left child or right child does not exist, the corresponding pointer field value is empty (denoted by the symbol ∧ or null). The chain storage structure of a two-fork tree, represented by such a node structure, is called a binary list, as shown in 5-8.
(a) a binary tree (b) Binary linked list storage structure
Fig. 5-8 representation of a two-fork tree in a two-fork list
To facilitate access to the parents of a node, you can also add a parent field to the linked list node, which is used to point to its parent node. Each node consists of four fields with a node structure of:
This storage structure makes it easy to find the children's nodes and find the parents ' nodes, but it increases the space overhead relative to the binary list storage structure. The chain storage structure of a two-fork tree, represented by such a node structure, is called a three-pronged list.
Figure 5-9 shows the three-prong list representation of a binary tree as shown in Figure 5-8 (a).
Fig. 5-9 representation of a cross-linked table with a two fork tree
Although it is not possible to find the parents directly from the node in the binary list, the two-fork linked list is flexible and easy to operate, and it can save space for the general situation of the two-fork tree, even more than the sequential storage structure. Therefore, the binary linked list is the most commonly used two-fork tree storage method.
Structure 5-2 Two fork-tree chained storage
#define DataType char // defines the data type of a binary tree element as a character
struct node // definition node consists of data fields, left and right pointers.
{Datatype data;
struct node *lchild,*rchild;
}bitree;
Binary linked list Storage binary tree