typescript-ds-lib
Version:
A collection of TypeScript data structure implementations
40 lines (39 loc) • 1.13 kB
TypeScript
import { Comparator } from '../types';
import { BaseCollection } from './base-collection';
export interface BinarySearchTree<T> {
insert(element: T): void;
remove(element: T): void;
find(element: T): boolean;
min(): T | undefined;
max(): T | undefined;
forEach(callback: (element: T) => void, traversal?: 'inorder' | 'preorder' | 'postorder'): void;
}
export declare class BinarySearchTree<T> extends BaseCollection<T> implements BinarySearchTree<T> {
private root;
private comparator;
private nodeCount;
constructor(comparator?: Comparator<T>);
private removeNode;
private findMin;
private isEqual;
private inorderTraversal;
private preorderTraversal;
private postorderTraversal;
/**
* Returns true if the BST is empty, false otherwise
*/
isEmpty(): boolean;
/**
* Removes all nodes from the BST
*/
clear(): void;
/**
* Returns the number of nodes in the BST.
*/
size(): number;
/**
* Checks if two BSTs are equal.
*/
equals(other: BinarySearchTree<T>): boolean;
private areTreesEqual;
}