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 d40c88a

Browse files
Depth first traversal pre order
1 parent fa3f45f commit d40c88a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

‎binarySearchTree.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ BST.prototype.contains = function(value) {
3232
};
3333

3434
BST.prototype.depthFirstTraversal = function(iteratorFunc, order) {
35+
if (order === "pre-order") iteratorFunc(this.value);
3536
if (this.left) this.left.depthFirstTraversal(iteratorFunc, order);
3637
if (order === "in-order") iteratorFunc(this.value);
3738
if (this.right) this.right.depthFirstTraversal(iteratorFunc, order);
@@ -55,4 +56,4 @@ function log(value) {
5556
console.log(value);
5657
}
5758

58-
bst.depthFirstTraversal(log, "in-order");
59+
bst.depthFirstTraversal(log, "pre-order");

0 commit comments

Comments
(0)

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