diff --git a/src/data-structures/binary-tree/abstract-binary-tree.ts b/src/data-structures/binary-tree/abstract-binary-tree.ts index a947efb..dcaea96 100644 --- a/src/data-structures/binary-tree/abstract-binary-tree.ts +++ b/src/data-structures/binary-tree/abstract-binary-tree.ts @@ -345,7 +345,7 @@ export abstract class AbstractBinaryTree= this.getHeight(beginRoot); } @@ -477,9 +475,8 @@ export abstract class AbstractBinaryTree 0; } @@ -532,8 +528,7 @@ export abstract class AbstractBinaryTree { @@ -661,7 +654,7 @@ export abstract class AbstractBinaryTree { @@ -669,7 +662,7 @@ export abstract class AbstractBinaryTree { - nodeOrPropertyName = nodeOrPropertyName ?? 'key'; + bfs(nodeOrPropertyName: NodeOrPropertyName = 'key'): AbstractBinaryTreeNodeProperties { this._clearResults(); const queue: Array = [this.root]; @@ -921,7 +911,7 @@ export abstract class AbstractBinaryTree { - pattern = pattern ?? 'in'; - nodeOrPropertyName = nodeOrPropertyName ?? 'key'; + dfs(pattern: DFSOrderPattern = 'in', nodeOrPropertyName: NodeOrPropertyName = 'key'): AbstractBinaryTreeNodeProperties { this._clearResults(); const _traverse = (node: N) => { switch (pattern) { @@ -980,7 +968,7 @@ export abstract class AbstractBinaryTree. */ - DFSIterative( - pattern?: 'in' | 'pre' | 'post', - nodeOrPropertyName?: NodeOrPropertyName + dfsIterative( + pattern: DFSOrderPattern = 'in', + nodeOrPropertyName: NodeOrPropertyName = 'key' ): AbstractBinaryTreeNodeProperties { - pattern = pattern || 'in'; - nodeOrPropertyName = nodeOrPropertyName || 'key'; this._clearResults(); if (!this.root) return this._getResultByPropertyName(nodeOrPropertyName); // 0: visit, 1: print @@ -1071,7 +1057,7 @@ export abstract class AbstractBinaryTree`. */ - levelIterative(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties { - nodeOrPropertyName = nodeOrPropertyName || 'key'; - node = node || this.root; + levelIterative(node: N | null = this.root, nodeOrPropertyName: NodeOrPropertyName = 'key'): AbstractBinaryTreeNodeProperties { if (!node) return []; this._clearResults(); @@ -1138,7 +1122,7 @@ export abstract class AbstractBinaryTree` objects. */ - listLevels(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperty[][] { - nodeOrPropertyName = nodeOrPropertyName || 'key'; - node = node || this.root; + listLevels(node: N | null = this.root, nodeOrPropertyName: NodeOrPropertyName = 'key'): AbstractBinaryTreeNodeProperty[][] { if (!node) return []; const levelsNodes: AbstractBinaryTreeNodeProperty[][] = []; @@ -1248,7 +1230,7 @@ export abstract class AbstractBinaryTree objects. */ morris( - pattern?: 'in' | 'pre' | 'post', - nodeOrPropertyName?: NodeOrPropertyName + pattern: DFSOrderPattern = 'in', + nodeOrPropertyName: NodeOrPropertyName = 'key' ): AbstractBinaryTreeNodeProperties { if (this.root === null) return []; - pattern = pattern || 'in'; - nodeOrPropertyName = nodeOrPropertyName || 'key'; - this._clearResults(); let cur: N | null | undefined = this.root; @@ -1452,8 +1431,8 @@ export abstract class AbstractBinaryTree`. */ - protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties { - nodeOrPropertyName = nodeOrPropertyName ?? 'key'; - + protected _getResultByPropertyName(nodeOrPropertyName: NodeOrPropertyName = 'key'): AbstractBinaryTreeNodeProperties { switch (nodeOrPropertyName) { case 'key': return this.visitedKey; diff --git a/src/data-structures/binary-tree/tree-multiset.ts b/src/data-structures/binary-tree/tree-multiset.ts index 9510db1..cdcd741 100644 --- a/src/data-structures/binary-tree/tree-multiset.ts +++ b/src/data-structures/binary-tree/tree-multiset.ts @@ -557,7 +557,7 @@ export class TreeMultiset = TreeMultiset */ DFSIterativeCount(pattern?: 'in' | 'pre' | 'post'): number[] { pattern = pattern ?? 'in'; - const nodes = super.DFSIterative(pattern, 'node'); + const nodes = super.dfsIterative(pattern, 'node'); return nodes.map(node => node.count); } diff --git a/src/interfaces/abstract-binary-tree.ts b/src/interfaces/abstract-binary-tree.ts index a8288ee..c7ff20c 100644 --- a/src/interfaces/abstract-binary-tree.ts +++ b/src/interfaces/abstract-binary-tree.ts @@ -122,17 +122,17 @@ export interface IAbstractBinaryTree; - DFSIterative(): BinaryTreeNodeKey[]; + dfsIterative(): BinaryTreeNodeKey[]; - DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[]; + dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[]; - DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[]; + dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[]; - DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[]; + dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[]; - DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[]; + dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[]; - DFSIterative( + dfsIterative( pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName ): AbstractBinaryTreeNodeProperties;