The clue of C + + realization of data structure two fork tree

Source: Internet
Author: User

We know that the two-fork tree is only a special two-fork tree, most of the nodes of the binary tree are not completely around the child, that is, many pointer fields are not fully utilized. On the other hand, when we are traversing a binary tree in some order, we get a sequence of characters, after which we can know the precursor of the node, that is to say, we can know very well the origin and the successor of any node. But this is based on the already-traversed foundation. On a binary list, we can only know the address of each node to its left and right child node, without knowing who the predecessor of a particular node is and who the successor is. To know, you have to traverse it once. Each time you need to know, you must traverse it once. Why not consider remembering these precursors and successors at the time of creation? That would be a lot of time saving.

After combining the analysis of the two angles, we can consider using those empty addresses to store the addresses of the precursors and subsequent nodes that point to the node in a traversal order. We refer to this precursor and subsequent pointer as a clue, plus a clue to the two-fork linked list called the Clue list, the corresponding two-fork tree is called the clue Two-fork tree (threaded Binary).

As shown in Figure 6-10-2, after the binary tree is iterated, the rchild in all the null pointer fields is changed to point to its successor node.

As shown in Figure 6-10-3, we take this binary tree in the middle sequence traversal, all the null pointer fields in the Lchild, to point to its predecessor nodes.

Through the figure 6-10-4 (hollow arrow solid line as the precursor, dashed black Arrows for the successor), it is easier to see that, in fact, the clue two fork tree, is tantamount to a binary tree into a two-way linked list, so that our insertion delete node, to find a node has brought convenience. So we call the process of a two-fork tree in some order to turn it into a clue two-fork tree.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.