📜  BSTNode root - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:41.380000             🧑  作者: Mango

代码示例1
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
}