title: How do I output the preorder traversal of a tree given the inorder and postorder tranversal?
body: <p>Given the code for outputing the postorder traversal of a tree when I have the preorder and the inorder traversal in an integer array. How do I similarly get the preorder with the inorder and postorder array given?</p>
  
  <pre><code>void postorder( int preorder[], int prestart, int inorder[], int inostart, int length)
  { 
    if(length==0) return; //terminating condition
    int i;
    for(i=inostart; i&lt;inostart+length; i++)
      if(preorder[prestart]==inorder[i])//break when found root in inorder array
        break;
    postorder(preorder, prestart+1, inorder, inostart, i-inostart);
    postorder(preorder, prestart+i-inostart+1, inorder, i+1, length-i+inostart-1);
    cout&lt;&lt;preorder[prestart]&lt;&lt;" ";
  }
  </code></pre>
  
  <p>Here is the prototype for preorder()</p>
  
  <p>void preorder( int inorderorder[], int inostart, int postorder[], int poststart, int length)</p>
  
  <p>to use postorder() it will be </p>
  
  <pre><code>int preorder[6]={6,4,1,5,8,9};
  int inorder[6]={1,4,5,6,8,9};
  postorder( preorder,0,inorder,0,6);
  </code></pre>
  
  <p>out put will be</p>
  
  <pre><code>1 5 4 9 8 6
  </code></pre>
  
  <p>below is the incorrect code for print_preorder(), still not working below</p>
  
  <pre><code>void print_preorder( int inorder[], int inostart, int postorder[], int poststart, int length)
      {
        if(length==0) return; //terminating condition
        int i;
        for(i=inostart; i&lt;inostart+length; i++)
          if(postorder[poststart+length-1]==inorder[i])
            break; 
        cout&lt;&lt;postorder[poststart+length-1]&lt;&lt;" ";
        print_preorder(inorder, inostart , postorder, poststart, i-inostart);
        print_preorder(inorder, inostart+i-poststart+1, postorder, i+1, length-i+inostart-1);
      }
  </code></pre>