Creation of data structure two fork tree

Source: Internet
Author: User

For example str---A (B (D (, G)), C, (e,f))


The scan uses the bracket notation to denote the binary tree string read to the symbol CH


Save parent nodes with a stack


The introduction of a variable K function is to specify whether the left child or the right child will be processed afterwards

K=1 treatment left child k=2 treatment right child


The situation is as follows

Create a node when a real letter is encountered

1 Encounters ch= Opening parenthesis adds the previously created node to the stack as a parent, k=1, indicating that the node that follows is the left child

2 Encounter ch= comma indicates that the node created after it is the right child node (the node refers to the actual letter otherwise invalid) k=2

3 encountered ch= closing parenthesis indicates that the left and right child of the node in the stack has been processed, back to the stack.


But the creation process is to always stack top elements as parent nodes.

Creation of data structure two fork tree

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.