Find postorder traversal of BST from preorder traversal | Run loop from 1 to length of pre ; Print from pivot length - 1 to zero ; Print from end to pivot length ; Driver Code
#include <iostream> NEW_LINE using namespace std ; void getPostOrderBST ( int pre [ ] , int N ) { int pivotPoint = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( pre [ 0 ] <= pre [ i ] ) { pivotPoint = i ; break ; } } for ( int i = pivotPoint - 1 ; i > 0 ; i -- ) { cout << pre [ i ] << " ▁ " ; } for ( int i = N - 1 ; i >= pivotPoint ; i -- ) { cout << pre [ i ] << " ▁ " ; } cout << pre [ 0 ] ; }