Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

check valid binary search tree java

public bool IsBinaryTree(Node node, int min = int.MinValue, int max = int.MaxValue)
{
    if (root == null)
    	return true;
    if (node.data < min || node.data > max)
    	return false;
        
    return  IsBinaryTree(node.leftChild,min,node.data-1) &&
    		IsBinaryTree(node.rightChild,node.data+1,max);
}

// node Structure
    public class Node
    {
        public int data;
        public Node leftChild;
        public Node rightChild;
        public Node(int data)
        {
            this.data = data;
        }
    }
 
PREVIOUS NEXT
Tagged: #check #valid #binary #search #tree #java
ADD COMMENT
Topic
Name
1+2 =