@@ -9,20 +9,13 @@ function _printTree(
9
9
hasLeftSibling : boolean = false
10
10
) : void {
11
11
if ( node === null ) return ;
12
-
13
- // Определяем текущий префикс для текущего узла
14
12
const currentPrefix = prefix + ( isRight ? ( hasLeftSibling ? "├── " : "└── " ) : hasLeftSibling == isRight ? "└── " : "├── " ) ;
15
13
console . log ( currentPrefix + node . val ) ;
16
-
17
- // Формируем префикс для потомков
18
14
const childPrefix = prefix + ( hasLeftSibling ? "│ " : " " ) ;
19
-
20
15
if ( node . left || node . right ) {
21
- // Сначала обрабатываем правый узел, чтобы он был сверху
22
16
if ( node . right ) {
23
17
_printTree ( node . right , childPrefix , true , node . left !== null ) ;
24
18
}
25
- // Затем обрабатываем левый узел, чтобы он был внизу
26
19
if ( node . left ) {
27
20
_printTree ( node . left , childPrefix , false , false ) ;
28
21
}
@@ -40,7 +33,6 @@ export function printTree(node: TreeNode): void {
40
33
if ( node . right ) {
41
34
_printTree ( node . right , childPrefix , true , node . left !== null ) ;
42
35
}
43
- // Затем обрабатываем левый узел, чтобы он был ниже
44
36
if ( node . left ) {
45
37
_printTree ( node . left , childPrefix , false , false ) ;
46
38
}
0 commit comments