Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0fb5eb5

Browse files
Get min max value binary tree
1 parent 8a76e90 commit 0fb5eb5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

‎binarySearchTree.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ BST.prototype.breadthFirstTraversal = function(iteratorFunc) {
4949
}
5050
};
5151

52+
BST.prototype.getMinVal = function() {
53+
if (this.left) return this.left.getMinVal();
54+
else return this.value;
55+
};
56+
57+
BST.prototype.getMaxVal = function() {
58+
if (this.right) return this.right.getMaxVal();
59+
else return this.value;
60+
};
61+
5262
let bst = new BST(50);
5363

5464
bst.insert(30);
@@ -67,4 +77,5 @@ function log(node) {
6777
console.log(node.value);
6878
}
6979

70-
bst.breadthFirstTraversal(log);
80+
console.log('MIN: ', bst.getMinVal());
81+
console.log('MAX: ', bst.getMaxVal());

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /