2023-08-23 15:03:19 +00:00
|
|
|
import {
|
|
|
|
AbstractBinaryTreeNodeProperties,
|
2023-08-23 16:01:44 +00:00
|
|
|
AbstractBinaryTreeNodeProperty,
|
2023-08-23 15:03:19 +00:00
|
|
|
BinaryTreeDeletedResult,
|
|
|
|
BinaryTreeNodeId,
|
|
|
|
BinaryTreeNodePropertyName,
|
2023-08-27 13:14:18 +00:00
|
|
|
DFSOrderPattern,
|
|
|
|
FamilyPosition,
|
2023-08-23 15:03:19 +00:00
|
|
|
LoopType,
|
|
|
|
NodeOrPropertyName
|
|
|
|
} from '../types';
|
2023-09-12 03:10:09 +00:00
|
|
|
import {AbstractBinaryTreeNode} from '../data-structures';
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 12:29:53 +00:00
|
|
|
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
|
2023-08-23 15:03:19 +00:00
|
|
|
|
|
|
|
get id(): BinaryTreeNodeId
|
|
|
|
|
|
|
|
set id(v: BinaryTreeNodeId)
|
|
|
|
|
2023-08-23 16:01:44 +00:00
|
|
|
get val(): T | undefined
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-23 16:01:44 +00:00
|
|
|
set val(v: T | undefined)
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 12:29:53 +00:00
|
|
|
get left(): NEIGHBOR | null | undefined
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 12:29:53 +00:00
|
|
|
set left(v: NEIGHBOR | null | undefined)
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 12:29:53 +00:00
|
|
|
get right(): NEIGHBOR | null | undefined
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 12:29:53 +00:00
|
|
|
set right(v: NEIGHBOR | null | undefined)
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 12:29:53 +00:00
|
|
|
get parent(): NEIGHBOR | null | undefined
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 12:29:53 +00:00
|
|
|
set parent(v: NEIGHBOR | null | undefined)
|
2023-08-23 15:03:19 +00:00
|
|
|
|
|
|
|
get familyPosition(): FamilyPosition
|
|
|
|
|
|
|
|
get height(): number
|
|
|
|
|
|
|
|
set height(v: number)
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
2023-08-28 00:40:31 +00:00
|
|
|
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null
|
2023-08-23 15:03:19 +00:00
|
|
|
|
|
|
|
get loopType(): LoopType
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-08-23 15:03:19 +00:00
|
|
|
get visitedId(): BinaryTreeNodeId[]
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-08-23 15:03:19 +00:00
|
|
|
get visitedVal(): Array<N['val']>
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-08-23 15:03:19 +00:00
|
|
|
get visitedNode(): N[]
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-08-23 15:03:19 +00:00
|
|
|
get visitedLeftSum(): number[]
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-08-23 15:03:19 +00:00
|
|
|
get root(): N | null
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-08-23 15:03:19 +00:00
|
|
|
get size(): number
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-08-28 12:04:43 +00:00
|
|
|
swapLocation(srcNode: N, destNode: N): N
|
|
|
|
|
2023-08-23 15:03:19 +00:00
|
|
|
clear(): void
|
|
|
|
|
|
|
|
isEmpty(): boolean
|
|
|
|
|
2023-08-31 12:02:31 +00:00
|
|
|
add(id: BinaryTreeNodeId | N, val?: N['val']): N | null | undefined
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-31 12:02:31 +00:00
|
|
|
addMany(idsOrNodes: (BinaryTreeNodeId | N | null)[], data?: N['val'][]): (N | null | undefined)[]
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-31 12:02:31 +00:00
|
|
|
fill(idsOrNodes: (BinaryTreeNodeId | N | null)[], data?: N[] | Array<N['val']>): boolean
|
2023-08-23 15:03:19 +00:00
|
|
|
|
|
|
|
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[]
|
|
|
|
|
|
|
|
getDepth(node: N): number
|
|
|
|
|
|
|
|
getHeight(beginRoot?: N | null): number
|
|
|
|
|
|
|
|
getMinHeight(beginRoot?: N | null): number
|
|
|
|
|
2023-08-29 09:29:57 +00:00
|
|
|
isPerfectlyBalanced(beginRoot?: N | null): boolean
|
2023-08-23 15:03:19 +00:00
|
|
|
|
|
|
|
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName ?: BinaryTreeNodePropertyName, onlyOne ?: boolean): N[]
|
|
|
|
|
|
|
|
has(nodeProperty: BinaryTreeNodeId | N, propertyName ?: BinaryTreeNodePropertyName): boolean
|
|
|
|
|
|
|
|
get(nodeProperty: BinaryTreeNodeId | N, propertyName ?: BinaryTreeNodePropertyName): N | null
|
|
|
|
|
|
|
|
getPathToRoot(node: N): N[]
|
|
|
|
|
|
|
|
getLeftMost(): N | null;
|
|
|
|
|
|
|
|
getLeftMost(node: N): N;
|
|
|
|
|
|
|
|
getLeftMost(node?: N | null): N | null
|
|
|
|
|
|
|
|
getRightMost(): N | null;
|
|
|
|
|
|
|
|
getRightMost(node: N): N;
|
|
|
|
|
|
|
|
getRightMost(node?: N | null): N | null
|
|
|
|
|
2023-08-31 14:25:41 +00:00
|
|
|
isSubtreeBST(node: N | null): boolean
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-08-31 14:25:41 +00:00
|
|
|
isBST(): boolean
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 09:29:57 +00:00
|
|
|
getSubTreeSize(subTreeRoot: N | null | undefined): number
|
2023-08-23 15:03:19 +00:00
|
|
|
|
|
|
|
// --- start additional methods ---
|
|
|
|
|
|
|
|
subTreeSum(subTreeRoot: N, propertyName ?: BinaryTreeNodePropertyName): number
|
|
|
|
|
|
|
|
subTreeAdd(subTreeRoot: N, delta: number, propertyName ?: BinaryTreeNodePropertyName): boolean
|
|
|
|
|
|
|
|
BFS(): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
|
|
|
|
|
|
BFS(nodeOrPropertyName: 'node'): N[];
|
|
|
|
|
|
|
|
BFS(nodeOrPropertyName: 'count'): number[];
|
|
|
|
|
|
|
|
BFS(nodeOrPropertyName ?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>
|
|
|
|
|
|
|
|
DFS(): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
|
|
|
|
|
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
|
|
|
|
|
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
|
|
|
|
|
|
DFS(pattern ?: 'in' | 'pre' | 'post', nodeOrPropertyName ?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>
|
|
|
|
|
|
|
|
DFSIterative(): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
|
|
|
|
|
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
|
|
|
|
|
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
|
|
|
|
|
|
DFSIterative(pattern ?: 'in' | 'pre' | 'post', nodeOrPropertyName ?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>
|
|
|
|
|
|
|
|
levelIterative(node: N | null): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
|
|
|
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
|
|
|
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
|
|
|
|
|
|
levelIterative(node: N | null, nodeOrPropertyName ?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>
|
|
|
|
|
|
|
|
listLevels(node: N | null): BinaryTreeNodeId[][];
|
|
|
|
|
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
|
|
|
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
|
|
|
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
|
|
|
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
|
|
|
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperty<N>[][]
|
|
|
|
|
|
|
|
getPredecessor(node: N): N
|
|
|
|
|
|
|
|
morris(): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
|
|
|
|
|
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
|
|
|
|
|
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
|
|
|
|
|
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
|
|
|
|
|
|
morris(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>
|
|
|
|
|
|
|
|
|
|
|
|
// --- end additional methods ---
|
|
|
|
}
|