human
What is a code to leaf nodes from Preorder of a Binary Search Tree ( Using Recursion ) and the other steps required given the following:
Leaf nodes from Preorder of a Binary Search Tree ( Using Recursion ) | Print the leaf node from the given preorder of BST ..
Driver code"
Solution in Python:
assistant
#Here is code to leaf nodes from Preorder of a Binary Search Tree ( Using Recursion ) and the other steps required.
 def isLeaf ( pre , i , n , Min , Max ) :
	if i [ 0 ] >= n :
		return False
	if pre [ i [ 0 ] ] > Min and pre [ i [ 0 ] ] < Max :
		i [ 0 ] += 1
		left = isLeaf ( pre , i , n , Min , pre [ i [ 0 ] - 1 ] )
		right = isLeaf ( pre , i , n , pre [ i [ 0 ] - 1 ] , Max )
		if left == False and right == False :
			print ( pre [ i [ 0 ] - 1 ] , end = " ▁ " )
		return True
	return False
def printLeaves ( preorder , n ) :
	i = [ 0 ]
	INT_MIN , INT_MAX = - 999999999999 , 999999999999
	isLeaf ( preorder , i , n , INT_MIN , INT_MAX )
if __name__ == ' _ _ main _ _ ' :
	preorder = [ 890 , 325 , 290 , 530 , 965 ]
	n = len ( preorder )
	printLeaves ( preorder , n )