Skip to content

Commit c35ce5c

Browse files
committed
fix paths
1 parent ac087e2 commit c35ce5c

21 files changed

+14
-29
lines changed

src/bst/problems/bfs-all-paths.task.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Graph } from "src/graph";
1+
import { Graph } from "src/graph/utilities";
22

33
export function bfsAllPaths(graph: Graph, start: string, end: string): string[][] {
44
const paths: string[][] = [];

src/bst/problems/bst-max-path-sum.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { printTree } from "..";
2-
import { TreeNode } from "../bst.structure";
1+
import { printTree, TreeNode } from "../utilities";
2+
33

44
function maxPathSum(root: TreeNode | null): number {
55
let maxSum = -Infinity;

src/bst/problems/bst-side-view.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
2-
import { printTree } from "../bst.utilities";
1+
import { printTree, TreeNode } from "../utilities";
32

43
function rightSideView(root: TreeNode | null): number[] {
54
const result: number[] = [];

src/bst/problems/delete.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
2-
import { printTree } from "../bst.utilities";
1+
import { printTree, TreeNode } from "../utilities";
32

43
function deleteNode(root: TreeNode | null, key: number): TreeNode | null {
54
if (!root) {

src/bst/problems/duplicates-subtrees.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
2-
import { printTree } from "../bst.utilities";
1+
import { printTree, TreeNode } from "../utilities";
32

43
function findDuplicateSubtrees(root: TreeNode | null): TreeNode[] {
54
const map = new Map<string, number>();

src/bst/problems/find-min.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
1+
import { TreeNode } from "../utilities";
22

33
function findMin(root: TreeNode | null): number | null {
44
if (!root) {

src/bst/problems/insert.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
2-
import { printTree } from "../bst.utilities";
1+
import { printTree, TreeNode } from "../utilities";
32

43
function insertIntoBST(root: TreeNode | null, val: number): TreeNode | null {
54
if (!root) {

src/bst/problems/is-balanced.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
1+
import { printTree, TreeNode } from "../utilities";
22

33
function isBalanced(root: TreeNode | null): boolean {
44
function checkBalance(node: TreeNode | null): number {

src/bst/problems/is-symmetric.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
1+
import { printTree, TreeNode } from "../utilities";
22

33
function isSymmetric(root: TreeNode | null): boolean {
44
if (!root) return true;

src/bst/problems/is-valid-bst.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
2-
import { printTree } from "../bst.utilities";
1+
import { printTree, TreeNode } from "../utilities";
32

43
function isValidBST(root: TreeNode | null, min?: number, max?: number): boolean {
54
const currentVal = root?.val;

src/bst/problems/lowest-common-ancestor.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { printTree } from "..";
2-
import { TreeNode } from "../bst.structure";
1+
import { printTree, TreeNode } from "../utilities";
32

43
function lowestCommonAncestor(root: TreeNode | null, p: TreeNode | null, q: TreeNode | null): TreeNode | null {
54
if (root === null || root === p || root === q) {

src/bst/problems/max-depth.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { printTree } from "..";
2-
import { TreeNode } from "../bst.structure";
1+
import { printTree, TreeNode } from "../utilities";
32

43
export namespace Recursion {
54
function maxDepth(root: TreeNode | null): number {

src/bst/problems/serialize-and-deserialize.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TreeNode } from "../bst.structure";
1+
import { printTree, TreeNode } from "../utilities";
22

33
function serialize(root: TreeNode): string {
44
const preorderSerialize = (node: TreeNode) => {
File renamed without changes.

src/bst/bst.utilities.ts renamed to src/bst/utilities/bst.utilities.ts

-8
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,13 @@ function _printTree(
99
hasLeftSibling: boolean = false
1010
): void {
1111
if (node === null) return;
12-
13-
// Определяем текущий префикс для текущего узла
1412
const currentPrefix = prefix + (isRight ? (hasLeftSibling ? "├── " : "└── ") : hasLeftSibling == isRight ? "└── ": "├── ");
1513
console.log(currentPrefix + node.val);
16-
17-
// Формируем префикс для потомков
1814
const childPrefix = prefix + (hasLeftSibling ? "│ " : " ");
19-
2015
if (node.left || node.right) {
21-
// Сначала обрабатываем правый узел, чтобы он был сверху
2216
if (node.right) {
2317
_printTree(node.right, childPrefix, true, node.left !== null);
2418
}
25-
// Затем обрабатываем левый узел, чтобы он был внизу
2619
if (node.left) {
2720
_printTree(node.left, childPrefix, false, false);
2821
}
@@ -40,7 +33,6 @@ export function printTree(node: TreeNode): void {
4033
if (node.right) {
4134
_printTree(node.right, childPrefix, true, node.left !== null);
4235
}
43-
// Затем обрабатываем левый узел, чтобы он был ниже
4436
if (node.left) {
4537
_printTree(node.left, childPrefix, false, false);
4638
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)