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