Given the code for outputing the postorder traversal of a tree when I have the preorder and the inorder traversal in an interger array. How do I similarily get the preorder with the inorder and postorder array given?
void postorder( int preorder[], int prestart, int inorder[], int inostart, int length)
{
if(length==0) return; //terminating condition
int i;
for(i=inostart; i<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<<preorder[prestart]<<" ";
}
Here is the prototype for preorder()
void preorder( int inorderorder[], int inostart, int postorder[], int poststart, int length)