dastal - v5.0.0 / Tree
Represents a tree data structure (source).
A tree is a widely used abstract data type that simulates a hierarchical tree structure. It can defined recursively as a collection of nodes (starting at a root node), where each node consists of a value and a list of references to other nodes ('children'), with the constraints that no reference is duplicated and none point to the root.
Iterate
- Iterate the tree: {@link [Symbol.iterator]}
Get
Set
- Update an element: update
Add
- Add 1 element: add
Remove
Name |
---|
T |
-
Collection<T>
↳ Tree
↳↳ SortedTree
• Readonly
size: number
The number of elements in the collection.
src/collection/collection.ts:5
▸ [iterator](): Iterator
<T, any, undefined>
Iterator
<T, any, undefined>
node_modules/typescript/lib/lib.es2015.iterable.d.ts:51
▸ add(element
): Tree<T>
Inserts an element into the tree.
Name | Type | Description |
---|---|---|
element |
T |
The element to be inserted. |
Tree<T>
The tree object.
▸ clear(): void
Removes all elements.
void
▸ delete(element
): boolean
Delete an element from the tree.
Name | Type | Description |
---|---|---|
element |
T |
The element to delete. |
boolean
true
if the element was found and deleted, otherwise false
.
▸ has(element
): boolean
Check if an element is in the tree.
Name | Type | Description |
---|---|---|
element |
T |
The element to find. |
boolean
true
if the element was found, otherwise false
.
▸ update(curElement
, newElement
): boolean
Update a specific element.
Name | Type | Description |
---|---|---|
curElement |
T |
The element to update. |
newElement |
T |
The new element to insert. |
boolean
true
if curElement was found and updated, otherwise false
.