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 7b65d6a

Browse files
committed
update: preorder traversal
1 parent f32e9aa commit 7b65d6a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ class BinarySearchTree {
2727
}
2828
return root;
2929
}
30+
31+
preorder(root) {
32+
if (root === null) return;
33+
// eslint-disable-next-line no-console
34+
console.log(`${root.value} `);
35+
36+
this.preorder(root.leftChild);
37+
this.preorder(root.rightChild);
38+
}
3039
}
3140

3241
// const bst = new BinarySearchTree(10);
@@ -39,4 +48,6 @@ class BinarySearchTree {
3948

4049
// console.log(bst.root);
4150

51+
// bst.preorder(bst.root);
52+
4253
module.exports = BinarySearchTree;

0 commit comments

Comments
(0)

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