Skip to content
Snippets Groups Projects
Commit d91754bb authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

add height() method to BST

parent 36cf6dd5
No related branches found
No related tags found
No related merge requests found
......@@ -174,4 +174,13 @@ public class BST<Key extends Comparable<Key>, Value> {
if (cmplo <= 0 && cmphi >= 0) al.add(x.key);
if (cmphi > 0) keys(x.right, al, lo, hi);
}
public int height() {
return height(root);
}
private int height(Node x) {
if (x == null) return 0;
else return Math.max(height (x.left), height(x.right)) + 1;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment