Last active
March 22, 2018 18:47
-
-
Save Abhishek9634/bf8f1b22d704a8b08a1cd40d19afa70a to your computer and use it in GitHub Desktop.
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
extension BinaryTree { | |
func search(element: T) { | |
self.search(self.rootNode, element) | |
} | |
private func search(_ rootNode: TreeNode<T>?, _ element: T) { | |
guard let rootNode = rootNode else { | |
print("INVALID NODE : \(element)") | |
return | |
} | |
print("ROOT NODE \(rootNode.data)") | |
if element > rootNode.data { | |
self.search(rootNode.rightNode, element) | |
} else if element < rootNode.data { | |
self.search(rootNode.leftNode, element) | |
} else { | |
print("NODE FOUND : \(rootNode.data)") | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment