We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e7dc20b commit aef601eCopy full SHA for aef601e
701. Insert into a Binary Search Tree/index.js
@@ -0,0 +1,24 @@
1
+const insertIntoBST = function(root, val) {
2
+ let iterator = root;
3
+
4
+ while (1) {
5
+ if (val > iterator.val) {
6
+ if (iterator.right) {
7
+ iterator = iterator.right;
8
+ } else {
9
+ iterator.right = new TreeNode(val);
10
+ console.log(iterator.right)
11
+ break;
12
+ }
13
14
+ if (iterator.left) {
15
+ iterator = iterator.left;
16
17
+ iterator.left = new TreeNode(val);
18
19
20
21
22
23
+ return root;
24
+};
0 commit comments