mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 04:44:04 +00:00
docs: Complete the documentation for the print method in BinaryTree. Correct the unit tests for the print method.
This commit is contained in:
parent
9ace395564
commit
6ef4b47b0b
|
@ -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<K, V, NODE> | 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<K, V, NODE> | R = this._root) {
|
||||
console.log(this.toVisual(beginRoot, options));
|
||||
}
|
||||
|
||||
protected _dfs<C extends BTNCallback<NODE>>(
|
||||
callback?: C,
|
||||
pattern?: DFSOrderPattern,
|
||||
beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
|
||||
iterationType?: IterationType
|
||||
): ReturnType<C>[];
|
||||
|
||||
protected _dfs<C extends BTNCallback<NODE | null>>(
|
||||
callback?: C,
|
||||
pattern?: DFSOrderPattern,
|
||||
beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
|
||||
iterationType?: IterationType,
|
||||
includeNull?: boolean
|
||||
): ReturnType<C>[];
|
||||
|
||||
/**
|
||||
* Time complexity: O(n)
|
||||
* Space complexity: O(n)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue