Print Postorder traversal from given Inorder and Preorder traversals | C # program to print Postorder traversal from given Inorder and Preorder traversals . ; Find index of next item in preorder traversal in inorder . ; traverse left tree ; traverse right tree ; print root node at the end of traversal ; Driver code
using System ; class GFG { public static int preIndex = 0 ; public virtual void printPost ( int [ ] arr , int [ ] pre , int inStrt , int inEnd ) { if ( inStrt > inEnd ) { return ; } int inIndex = search ( arr , inStrt , inEnd , pre [ preIndex ++ ] ) ; printPost ( arr , pre , inStrt , inIndex - 1 ) ; printPost ( arr , pre , inIndex + 1 , inEnd ) ; Console . Write ( arr [ inIndex ] + " ▁ " ) ; } public virtual int search ( int [ ] arr , int startIn , int endIn , int data ) { int i = 0 ; for ( i = startIn ; i < endIn ; i ++ ) { if ( arr [ i ] == data ) { return i ; } } return i ; } public static void Main ( string [ ] ars ) { int [ ] arr = new int [ ] { 4 , 2 , 5 , 1 , 3 , 6 } ; int [ ] pre = new int [ ] { 1 , 2 , 4 , 5 , 3 , 6 } ; int len = arr . Length ; GFG tree = new GFG ( ) ; tree . printPost ( arr , pre , 0 , len - 1 ) ; } }