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
function getPostOrderBST ( pre , N ) { var pivotPoint = 0 ; for ( var i = 1 ; i < N ; i ++ ) { if ( pre [ 0 ] <= pre [ i ] ) { pivotPoint = i ; break ; } } for ( var i = pivotPoint - 1 ; i > 0 ; i -- ) { document . write ( pre [ i ] + " " ) ; } for ( var i = N - 1 ; i >= pivotPoint ; i -- ) { document . write ( pre [ i ] + " " ) ; } document . write ( pre [ 0 ] ) ; }