Print the leaf node from the given preorder of BST .
public static void leafNode ( int [ ] preorder , int n ) { Stack < int > s = new Stack < int > ( ) ; for ( int i = 0 , j = 1 ; j < n ; i ++ , j ++ ) { bool found = false ; if ( preorder [ i ] > preorder [ j ] ) { s . Push ( preorder [ i ] ) ; } else { while ( s . Count > 0 ) { if ( preorder [ j ] > s . Peek ( ) ) { s . Pop ( ) ; found = true ; } else { break ; } } } if ( found ) { Console . Write ( preorder [ i ] + " ▁ " ) ; } }