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 9033d3a

Browse files
committed
update: added getMaximum
1 parent b62984b commit 9033d3a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎src/_DataStructures_/Trees/BST/index.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ class BinarySearchTree {
121121
return this.findMinNode(root.leftChild);
122122
}
123123

124+
findMaxNode(root) {
125+
if (root.rightChild === null) return root;
126+
return this.findMaxNode(root.rightChild);
127+
}
128+
124129
isEmpty() {
125130
return this.root === null;
126131
}
@@ -147,11 +152,16 @@ class BinarySearchTree {
147152
return this.search(this.root, value);
148153
}
149154

150-
findMinimum() {
155+
getMinimum() {
151156
const minNode = this.findMinNode(this.root);
152157
return minNode.value;
153158
}
154159

160+
getMaximum() {
161+
const maxNode = this.findMaxNode(this.root);
162+
return maxNode.value;
163+
}
164+
155165
remove(value) {
156166
return this.delete(this.root, value);
157167
}
@@ -180,9 +190,12 @@ class BinarySearchTree {
180190
// const search = 18;
181191
// console.log(`Search for ${search}`, bst.searchFor(search));
182192

183-
// const minNode = bst.findMinimum();
193+
// const minNode = bst.getMinimum();
184194
// console.log('Minimum value =>', minNode);
185195

196+
// const maxNode = bst.getMaximum();
197+
// console.log('Maximum value =>', maxNode);
198+
186199
// bst.remove(4);
187200
// console.log(bst.traversePreorder());
188201

0 commit comments

Comments
(0)

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