import Optional from './Optional'; declare class TreeNode { value: T; left?: TreeNode; right?: TreeNode; constructor(value: T); } /** * Represents a binary search tree. * @template T - The type of elements stored in the tree. */ export default class Tree { private readonly compare; root?: TreeNode; /** * Creates a new Tree instance. * @param {T} value - The value of the root node. * @param {(a: T, b: T) => number} compareFunction - The function used to compare elements. */ constructor(value: T, compareFunction: (a: T, b: T) => number); /** * Creates a new tree node with the given value. * @param {T} value - The value of the node. * @returns {TreeNode} - The created tree node. */ private createNode; /** * Inserts a new value into the tree. * @param {T} value - The value to insert. */ insert: (value: T) => void; /** * Recursively inserts a value into the tree. * @param {TreeNode | undefined} root - The root node of the subtree. * @param {T} value - The value to insert. * @returns {TreeNode} - The updated root of the subtree. */ private insertNode; /** * Searches for a value in the tree. * @param {T} value - The value to search for. * @returns {Optional>} - An Optional containing the found node or undefined. */ search: (value: T) => Optional>; /** * Recursively searches for a value in the tree. * @param {TreeNode | undefined} root - The root node of the subtree. * @param {T} value - The value to search for. * @returns {TreeNode | undefined} - The found node or undefined. */ private searchNode; /** * Performs an in-order traversal of the tree, applying the callback to each node's value. * @param {(value: T) => void} callback - The callback function to apply to each node's value. */ inOrderTraversal: (callback: (value: T) => void) => void; /** * Recursively performs an in-order traversal of the tree. * @param {TreeNode | undefined} root - The root node of the subtree. * @param {(value: T) => void} callback - The callback function to apply to each node's value. */ private inOrderTraversalNode; /** * Performs a pre-order traversal of the tree, applying the callback to each node's value. * @param {(value: T) => void} callback - The callback function to apply to each node's value. */ preOrderTraversal: (callback: (value: T) => void) => void; /** * Recursively performs a pre-order traversal of the tree. * @param {TreeNode | undefined} root - The root node of the subtree. * @param {(value: T) => void} callback - The callback function to apply to each node's value. */ private preOrderTraversalNode; /** * Performs a post-order traversal of the tree, applying the callback to each node's value. * @param {(value: T) => void} callback - The callback function to apply to each node's value. */ postOrderTraversal: (callback: (value: T) => void) => void; /** * Recursively performs a post-order traversal of the tree. * @param {TreeNode | undefined} root - The root node of the subtree. * @param {(value: T) => void} callback - The callback function to apply to each node's value. */ private postOrderTraversalNode; /** * Finds the minimum value in the tree. * @returns {Optional>} - An Optional containing the node with the minimum value or undefined. */ findMin: () => Optional>; /** * Finds the maximum value in the tree. * @returns {Optional>} - An Optional containing the node with the maximum value or undefined. */ findMax: () => Optional>; /** * Removes a value from the tree if it exists. * @param {T} value - The value to remove. */ remove: (value: T) => void; /** * Recursively removes a node from the tree. * @param {TreeNode | undefined} root - The root node of the subtree. * @param {T} value - The value to remove. * @returns {TreeNode | undefined} - The updated subtree root. */ private removeNode; /** * Gets the node with the minimum value in the subtree. * @param {TreeNode} root - The root node of the subtree. * @returns {TreeNode | undefined} - The node with the minimum value. */ private getMinNode; } export {};