File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -31,10 +31,10 @@ BST.prototype.contains = function(value) {
31
31
}
32
32
} ;
33
33
34
- BST . prototype . depthFirstTraversal = function ( iteratorFunc ) {
35
- if ( this . left ) this . left . depthFirstTraversal ( iteratorFunc ) ;
36
- iteratorFunc ( this . value ) ;
37
- if ( this . right ) this . right . depthFirstTraversal ( iteratorFunc ) ;
34
+ BST . prototype . depthFirstTraversal = function ( iteratorFunc , order ) {
35
+ if ( this . left ) this . left . depthFirstTraversal ( iteratorFunc , order ) ;
36
+ if ( order === "in-order" ) iteratorFunc ( this . value ) ;
37
+ if ( this . right ) this . right . depthFirstTraversal ( iteratorFunc , order ) ;
38
38
} ;
39
39
40
40
let bst = new BST ( 50 ) ;
@@ -55,4 +55,4 @@ function log(value) {
55
55
console . log ( value ) ;
56
56
}
57
57
58
- bst . depthFirstTraversal ( log ) ;
58
+ bst . depthFirstTraversal ( log , "in-order" ) ;
You can’t perform that action at this time.
0 commit comments