HDU 17,102 cross-tree traversal

Source: Internet
Author: User

#include <iostream> #include <stack>using namespace std;typedef struct node{     Node *l,*r;    Both struct node and node  can be  int num;} *tree;tree root;tree creat (int a[],int b[],int n) {tree ss;for (int i=0;i<n;i++) {if (a[0] = = B[i]) {            SS = (tree) Mallo C (sizeof (Node)); ss->num = B[i];ss->l=creat (a+1,b,i); Ss->r=creat (a+i+1,b+i+1,n-i-1); return SS;}} return NULL;} void Post_order (tree h) {     if (H!=null)     //if judgment must not be less, because where the leaves are stopped,     {post_order (h->l);p Ost_order (H- >R); if (root = = h) {Cout<


The root node is obtained from the binate sequence traversal and the middle sequence traversal, and then the left (left subtree) and the right (right subtree) of the root are traversed according to the middle sequence, and then the root is recursively found.

HDU 17,102 cross-tree traversal

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.