Skip to content
Snippets Groups Projects
Commit c89eda2b authored by Philippe Suter's avatar Philippe Suter
Browse files

No commit message

No commit message
parent c1cb0e7c
Branches
Tags
No related merge requests found
......@@ -20,9 +20,13 @@ object BinarySearchTree {
def contains(tree: Tree, value: Int) : Boolean = tree match {
case Leaf() => false
case Node(_, v, _) if v == value => true
case Node(l, v, r) if v < value => contains(r, value)
case Node(l, v, r) if v > value => contains(l, value)
case n @ Node(l, v, r) => if(v < value) {
contains(r, value)
} else if(v > value) {
contains(l, value)
} else {
true
}
}
def contents(tree: Tree) : Set[Int] = tree match {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment