[Binary Tree] Build a binary tree

Source: Internet
Author: User

There are two prerequisites for building a binary tree

[Prerequisite 1]

Build a binary tree based on the input (first | Middle | back) sequential traversal sequence (null values are replaced by #), such as AB # C # def.

[Prerequisite 2]

Build a binary tree based on any two input traversal sequences, such as abcedfg and ecbdfag.

There are two ways to build a binary tree

Method 1]

Recursion

Method 2]

Non-recursion

What you need to know

  • Each node in the first sequence is actually the root node of its subtree.
  • Each node in the central sequence divides the sequence into two parts: left and right. The sequence on the left of the node is the left subtree of the node, and the sequence on the right of the node is the right subtree of the node.
Some useful c Functions
  • Strchr (const char * s, char C): locate the first occurrence of character C in string s

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.