Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

BSTNode root

void storeInorder(BSTNode root, int arr[])
{
    if (root == NULL)
        return
    storeInorder(root.left, arr)
    arr.append(root.val)
    storeInorder(root.right, arr)
}
boolean isBST(BSTNode root)
{
    int arr[]   // Auxiliary array to store inorder 
    storeInorder(root, arr) // Traverses the array in inorder fashion and stores the result in arr
    // Lets check if arr is in sorted order or not
    for(i = 1 to arr.length - 1)
        if (arr[i] < arr[i-1])
            return False 
    return True
}
Source by afteracademy.com #
 
PREVIOUS NEXT
Tagged: #BSTNode #root
ADD COMMENT
Topic
Name
8+8 =