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 78cb213 commit 5fd958eCopy full SHA for 5fd958e
src/_DataStructures_/Trees/BST/index.js
@@ -41,6 +41,7 @@ class BinarySearchTree {
41
}
42
43
inorder(root) {
44
+ /** left - root - right */
45
if (root === null) return [];
46
let arr = [];
47
const left = this.inorder(root.leftChild);
@@ -53,6 +54,21 @@ class BinarySearchTree {
53
54
arr = [...arr, ...right];
55
return arr;
56
57
+
58
+ postorder(root) {
59
+ /** left - right - root */
60
61
+ if (root === null) return [];
62
+ let arr = [];
63
64
+ const left = this.postorder(root.leftChild);
65
+ arr = [...left, ...arr];
66
67
+ const right = this.postorder(root.rightChild);
68
+ arr = [...arr, ...right];
69
70
+ return [...arr, root.value];
71
+ }
72
73
74
// const bst = new BinarySearchTree(6);
@@ -72,4 +88,7 @@ class BinarySearchTree {
88
// const inorder = bst.inorder(bst.root);
89
// console.log('Inorder Traversal - ', inorder);
90
91
+// const postorder = bst.postorder(bst.root);
92
+// console.log('Postorder Traversal - ', postorder);
93
75
94
module.exports = BinarySearchTree;
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments