Advertisement
Guest User

Check if a given array is a post order traversal of a BST.

a guest
Oct 31st, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.32 KB | None | 0 0
  1. public static boolean isPostOrder(int[] array) {
  2.        
  3.         int root = array[array.length - 1];
  4.        
  5.         int i = 0;
  6.        
  7.         while(array[i] < root) {
  8.             i++;
  9.         }
  10.        
  11.         while(array[i] > root) {
  12.             i++;
  13.         }
  14.        
  15.     return i == array.length - 1;
  16.    
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement