BinarySearchTree
We can indicate the comparasion rule by constructor parameter which will be used for greater left instead of smaller left by default.
For search
, insert
, delete
operations that travel the tree,
there are two versions:
- iterative operation,
- recursive one, in which function name is initialized with a
r
.
Always choose iterative operations as a recommandation in JavaScript
.
We have defined different traversal way in tango.type.TRAVERSAL.*
.
The default traversal way is tango.type.TRAVERSAL.IN_ORDER
.
search(elem): node
Searches elem
in this tree, returns node which containselem
, or null
if not exsits.
Recursive version is rSearch(elem): node
.
insert(elem): void
Inserts elem
under BST
order, no duplication.
Recursive version is rInsert(elem): void
.
forEach(t: TRAVERSAL, fn): void
Travels and applies function fn
on this BST
tree with specific tango.type.TRAVERSAL
order.
Recursive version is rForEach(t: TRAVERSAL, fn): void
.
map(t: TRAVERSAL, fn): [any]
Maps each element of this BST
tree into an array with specific tango.type.TRAVERSAL
order.
Recursive version is rMap(t: TRAVERSAL, fn): void
.