diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index ee78907..d43c078 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -1703,25 +1703,25 @@ export class BinaryTree< return output; } + /** + * Time Complexity: O(n) + * Space Complexity: O(n) + * + * The function `print` in TypeScript overrides the default print behavior to log a visual + * representation of the binary tree to the console. + * @param {BinaryTreePrintOptions} [options] - The `options` parameter is used to specify the + * printing options for the binary tree. It is an optional parameter that allows you to customize how + * the binary tree is printed, such as choosing between different traversal orders or formatting + * options. + * @param {BTNKeyOrNodeOrEntry | R} beginRoot - The `beginRoot` parameter in the + * `override print` method is used to specify the starting point for printing the binary tree. It can + * be either a key, a node, an entry, or the root of the tree. If no specific starting point is + * provided, the default value is set to + */ override print(options?: BinaryTreePrintOptions, beginRoot: BTNKeyOrNodeOrEntry | R = this._root) { console.log(this.toVisual(beginRoot, options)); } - protected _dfs>( - callback?: C, - pattern?: DFSOrderPattern, - beginRoot?: BTNKeyOrNodeOrEntry | R, - iterationType?: IterationType - ): ReturnType[]; - - protected _dfs>( - callback?: C, - pattern?: DFSOrderPattern, - beginRoot?: BTNKeyOrNodeOrEntry | R, - iterationType?: IterationType, - includeNull?: boolean - ): ReturnType[]; - /** * Time complexity: O(n) * Space complexity: O(n) diff --git a/test/unit/data-structures/binary-tree/binary-tree.test.ts b/test/unit/data-structures/binary-tree/binary-tree.test.ts index 067d781..309668e 100644 --- a/test/unit/data-structures/binary-tree/binary-tree.test.ts +++ b/test/unit/data-structures/binary-tree/binary-tree.test.ts @@ -319,27 +319,26 @@ describe('BinaryTree', () => { it('should isSubtreeBST', () => { expect(tree.toVisual()).toBe(''); tree.addMany([4, 2, 6, 1, 3, 5, 7, 4]); - expect(tree.toVisual()).toBe( + expect(tree.toVisual()).toBe('N for null\n' + ' ___4___ \n' + - ' / \\ \n' + - ' _2_ _6_ \n' + - ' / \\ / \\ \n' + - ' 1 3 5 7 \n' + - ' \n' - ); + ' / \\ \n' + + ' _2_ _6_ \n' + + ' / \\ / \\ \n' + + ' 1 3 5 7 \n' + + ' \n'); const visualized = tree.toVisual(undefined, { isShowUndefined: true, isShowNull: true, isShowRedBlackNIL: true }); expect(visualized).toBe( 'U for undefined\n' + - ' N for null\n' + - ' S for Sentinel Node(NIL)\n' + - ' _______4_______ \n' + - ' / \\ \n' + - ' ___2___ ___6___ \n' + - ' / \\ / \\ \n' + - ' _1_ _3_ _5_ _7_ \n' + - ' / \\ / \\ / \\ / \\ \n' + - ' U U U U U U U U \n' + - ' \n' + 'N for null\n' + + 'S for Sentinel Node(NIL)\n' + + ' _______4_______ \n' + + ' / \\ \n' + + ' ___2___ ___6___ \n' + + ' / \\ / \\ \n' + + ' _1_ _3_ _5_ _7_ \n' + + ' / \\ / \\ / \\ / \\ \n' + + ' U U U U U U U U \n' + + ' \n' ); expect(tree.isBST(tree.getNode(4), 'RECURSIVE')).toBe(true);