Leaf nodes from Preorder of a Binary Search Tree ( Using Recursion ) | Recursive C # program to find leaf nodes from given preorder traversal ; Print the leaf node from the given preorder of BST . ; Driver code
using System ; class GFG { static int i = 0 ; static bool isLeaf ( int [ ] pre , int n , int min , int max ) { if ( i >= n ) { return false ; } if ( pre [ i ] > min && pre [ i ] < max ) { i ++ ; bool left = isLeaf ( pre , n , min , pre [ i - 1 ] ) ; bool right = isLeaf ( pre , n , pre [ i - 1 ] , max ) ; if ( ! left && ! right ) { Console . Write ( pre [ i - 1 ] + " ▁ " ) ; } return true ; } return false ; } static void printLeaves ( int [ ] preorder , int n ) { isLeaf ( preorder , n , int . MinValue , int . MaxValue ) ; } public static void Main ( String [ ] args ) { int [ ] preorder = { 890 , 325 , 290 , 530 , 965 } ; int n = preorder . Length ; printLeaves ( preorder , n ) ; } }