Created
November 18, 2018 18:40
-
-
Save AlexeiDarmin/a82bc5d194535fd9d4b9831b6e51e11a to your computer and use it in GitHub Desktop.
Implement a function to validate that a binary tree is a binary search tree.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Valiate binary tree: Implement a function to validate that a binary tree is a binary search tree. | |
function validateBST<T>(node: BinaryNode<T>) { | |
if (!node) return true | |
if (node.leftChild && node.leftChild.data > node.data) return false | |
if (node.rightChild && node.rightChild.data < node.data) return false | |
return validateBST(node.leftChild) && validateBST(node.rightChild) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment