[C ++] Data Structure: A Recursive Method for Finding the descending order in the first order known in the binary tree

Source: Internet
Author: User
# Include <iostream> using namespace STD; const int maxsize = 20; // The maximum size of the array int P; // a temporary number is used to mark the position of the array in the current operation char midorder [maxsize]; // used to store the char preorder [maxsize] array in the sequential traversal order; // used to store arrays in the first traversal order // initialization method void Init () {cout <"in-order:"; CIN> midorder; cout <"pre-order:"; CIN> preorder; cout <"post-order:"; P = 0 ;} // recursively output the post-order traversal method void find (char mid [maxsize]) {int Q; char temp [maxsize]; If (mid [0] = NULL) return; for (INT I = 0; m Id [I]! = '\ 0'; I ++) {If (mid [I] = preorder [p]) {q = I; // obtain the Q // that is, the Q-th Column in the current array is the root node} for (I = 0; I <q; I ++) {temp [I] = mid [I]; // Save the node before the root node to the T array} temp [Q] = '\ 0 '; // mark the end of the string P ++; find (temp); // continue the subtree before the root node for (I = q + 1; mid [I]! = '\ 0'; I ++) // pass the node back to the temp array temp [i-q-1] = mid [I]; temp [strlen (MID) -1-Q] = '\ 0'; // Add \ 0 to the end of the string. Find (temp ); // The subtree after the root node continues to traverse cout in the descending order <mid [Q]; // Finally, return;} void main () {Init (); find (midorder); cout <Endl ;}

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.