File tree 1 file changed +15
-2
lines changed
src/_DataStructures_/Trees/BST
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,11 @@ class BinarySearchTree {
121
121
return this . findMinNode ( root . leftChild ) ;
122
122
}
123
123
124
+ findMaxNode ( root ) {
125
+ if ( root . rightChild === null ) return root ;
126
+ return this . findMaxNode ( root . rightChild ) ;
127
+ }
128
+
124
129
isEmpty ( ) {
125
130
return this . root === null ;
126
131
}
@@ -147,11 +152,16 @@ class BinarySearchTree {
147
152
return this . search ( this . root , value ) ;
148
153
}
149
154
150
- findMinimum ( ) {
155
+ getMinimum ( ) {
151
156
const minNode = this . findMinNode ( this . root ) ;
152
157
return minNode . value ;
153
158
}
154
159
160
+ getMaximum ( ) {
161
+ const maxNode = this . findMaxNode ( this . root ) ;
162
+ return maxNode . value ;
163
+ }
164
+
155
165
remove ( value ) {
156
166
return this . delete ( this . root , value ) ;
157
167
}
@@ -180,9 +190,12 @@ class BinarySearchTree {
180
190
// const search = 18;
181
191
// console.log(`Search for ${search}`, bst.searchFor(search));
182
192
183
- // const minNode = bst.findMinimum ();
193
+ // const minNode = bst.getMinimum ();
184
194
// console.log('Minimum value =>', minNode);
185
195
196
+ // const maxNode = bst.getMaximum();
197
+ // console.log('Maximum value =>', maxNode);
198
+
186
199
// bst.remove(4);
187
200
// console.log(bst.traversePreorder());
188
201
You can’t perform that action at this time.
0 commit comments