Korzeń BSTNODE
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
}
Ashamed Anteater