We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1dd93ad commit 528a810Copy full SHA for 528a810
binary_search_tree/Tree.js
@@ -178,6 +178,15 @@ class Tree {
178
);
179
}
180
181
+ rebalance() {
182
+ if (this.checkIsBalanced()) return;
183
+
184
+ const arrayOfNodes = this.levelOrder((node) => node.data);
185
+ this.root = this.buildTree(arrayOfNodes);
186
187
+ return this.root;
188
+ }
189
190
print(node = this.root, prefix = "", isLeft = true) {
191
if (node === null) {
192
return;
binary_search_tree/index.js
@@ -32,5 +32,5 @@ console.log(tree.checkIsBalanced());
32
33
tree.insert(2.5);
34
tree.print();
35
-
36
-console.log(tree.checkIsBalanced());
+tree.rebalance();
+tree.print();
0 commit comments