LinkedBinaryTree
A tree in which element can have either zero, one or two children. This structure is link-based.
length
/**
* Number of elements in the tree.
*
* @readonly
*/
get length(): numberaddLeft()
/**
* Adds element as the left child of the specified position. Throws an error if left child already exists.
*
* @param position Position in the tree.
* @param element Element to add.
* @returns Position of the added element.
*/
addLeft(position: P, element: T): PaddRIght()
/**
* Adds element as the right child of the specified position. Throws an error if right child already exists.
*
* @param position Position in the tree.
* @param element Element to add.
* @returns Position of the added element.
*/
addRight(position: P, element: T): PaddRoot()
/**
* Adds the specified element at the root of the tree. Throws an error if the tree is not empty.
*
* @param element Element to add.
* @returns Position of the added element.
*/
addRoot(element: T): Position<T, Node<T>>areEqual()
/**
* Checks whether the specified positions are of the same element.
*
* @param a Position in the tree.
* @param b Position in the tree.
* @returns TRUE if the positions are the same, FALSE otherwise.
*/
areEqual(a: P, b: P): booleanattachLeft()
/**
* Attaches elements structure of the specified tree as the left child of the position.
* Throws an error if left child already exists.
*
* @param position Position in the tree.
* @param tree Tree to attach.
*/
attachLeft(position: P, tree: this)attachRight()
/**
* Attaches elements structure of the specified tree as the right child of the position.
* Throws an error if right child already exists.
*
* @param position Position in the tree.
* @param tree Tree to attach.
*/
attachRight(position: P, tree: this)clear()
/**
* Clears the tree. If instant set TRUE it takes O(1) time but does not deprecate the existing positions.
*
* @param instant TRUE to deprecate all existing positions, FALSE to skip deprecation (client code cares of it).
*/
clear(instant = false)getChildren()
/**
* Gets iteration of children of the specified position in the tree.
*
* @param position Position in the tree.
* @returns Iterable iterator of positions.
*/
getChildren(position: P): IterableIterator<P>getLeft()
/**
* Gets left child of the specified position.
*
* @param position Position in the tree.
* @returns Position or undefined if the specified position has no left child.
*/
getLeft(position: P): P | undefinedgetNumChildren()
/**
* Gets count of children of the specified position in the tree.
*
* @param position Position in the tree.
* @returns Number of children. Zero if position is of a leaf element.
*/
getNumChildren(position: P): numbergetDepth()
/**
* Gets number of levels separating the specified position from the root.
*
* @param position Position in the tree. No position to get the depth of the tree.
* @returns Number of levels.
*/
getDepth(position: P): numbergetHeight()
/**
* Gets the maximum number of levels separating the specified position from the tree's leaves.
*
* @param position Position in the tree. No position to get the height of the tree.
* @returns Number of levels.
*/
getHeight(position?: P): numbergetParent()
/**
* Gets parent of the specified position in the tree.
*
* @param position Position in the tree.
* @returns Position or undefined if the specified position is of the root.
*/
getParent(position: P): P | undefinedgetRight()
/**
* Gets right child of the specified position.
*
* @param position Position in the tree.
* @returns Position or undefined if the specified position has no right child.
*/
getRight(position: P): P | undefinedgetRoot()
/**
* Gets position of the root element of the tree.
*
* @returns Position of the root element.
*/
getRoot(): P | undefinedgetSibling()
/**
* Gets sibling of the specified position.
*
* @param position Position in the tree.
* @returns Position or undefined if the specified position has no sibling.
*/
getSibling(position: P): P | undefinedhasLeft()
/**
* Checks existence of a left child for the specified position.
*
* @param position Position in the tree.
* @returns TRUE if position has left child, FALSE otherwise.
*/
hasLeft(position: P): booleanhasRight()
/**
* Checks existence of a right child for the specified position.
*
* @param position Position in the tree.
* @returns TRUE if position has right child, FALSE otherwise.
*/
hasRight(position: P): booleanhasSibling()
/**
* Checks existence of a sibling for the specified position.
*
* @param position Position in the tree.
* @returns TRUE if position has sibling, FALSE otherwise.
*/
hasSibling(position: P): booleanisEmpty()
/**
* Checks whether the tree is empty or not.
*
* @returns TRUE if the tree is empty, FALSE otherwise.
*/
isEmpty(): booleanisLeaf()
/**
* Checks whether the specified position is of a leaf element in the tree.
*
* @param position Position in the tree.
* @returns TRUE if the position's element is leaf, FALSE otherwise.
*/
isLeaf(position: P): booleanisLeftChild()
/**
* Checks whether the first specified position is the left child of the second.
*
* @param a Position in the tree.
* @param b Position in the tree.
* @returns TRUE if the positions are in parent->left child relation, FALSE otherwise.
*/
isLeftChild(a: P, b: P): booleanisRightChild()
/**
* Checks whether the first specified position is the right child of the second.
*
* @param a Position in the tree.
* @param b Position in the tree.
* @returns TRUE if the positions are in parent->right child relation, FALSE otherwise.
*/
isRightChild(a: P, b: P): booleanisRoot()
/**
* Checks whether the specified position is of the root element in the tree.
*
* @param position Position in the tree.
* @returns TRUE if the position's element is root, FALSE otherwise.
*/
isRoot(position: P): booleanremove()
/**
* Removes element from the tree by position and returns it. Throws an error if the position is not valid
* or has more than one child.
*
* @param position Position of the element.
* @returns Removed element.
*/
remove(position: Position<T, Node<T>>): Treplace()
/**
* Replaces element at the specified position.
*
* @param position Position of the element.
* @param element Element to replace the existing with.
* @returns Replaced element.
*/
replace(position: Position<T, Node<T>>, element: T): Ttraverse()
/**
* Accepts traversal to traverse through the elements of the tree.
*
* @param traversal Tree traversal algorithm.
*/
traverse<R, M extends ITraversalMetadata>(traversal: TreeTraversalAbstract<T, R, this, M>): RLast updated
Was this helpful?