Skip to content

Commit 048f10f

Browse files
committed
MirrorTree task: add YT link, adjust solution+test
1 parent 1fb716c commit 048f10f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ they contain enough code which describes implementation in a natural way.
253253
| Определение высоты бинарного дерева | [Youtube](https://youtu.be/xTftgqH0WVI) | [Code](src/main/java/by/andd3dfx/tree/TreeHeight.java) |
254254
| Dummy, Fake, Stub, Spy, Mock | [Youtube](https://youtu.be/KkXqW8vMD-4) | - |
255255
| Нагрузочное тестирование Spring Boot сервиса с помощью Gatling | [Youtube](https://youtu.be/uO9luM8wowo) | [Repo](https://github.com/andrei-punko/articles-backend-app) |
256+
| Отражение бинарного дерева | [Youtube](https://youtu.be/H2BBCUcVXDM) | [Code](src/main/java/by/andd3dfx/tree/MirrorTree.java) |
256257

257258
## Materials & notes
258259

src/main/java/by/andd3dfx/tree/MirrorTree.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
/**
66
* Mirror binary tree: for each node left & right sub nodes should be swapped
7+
*
8+
* @see <a href="https://youtu.be/H2BBCUcVXDM">Video solution</a>
79
*/
810
public class MirrorTree {
911

@@ -12,9 +14,9 @@ public static Node mirror(Node node) {
1214
return null;
1315
}
1416

15-
var oldLeft = mirror(node.left);
17+
var oldLeft = node.left;
1618
node.left = mirror(node.right);
17-
node.right = oldLeft;
19+
node.right = mirror(oldLeft);
1820
return node;
1921
}
2022

src/test/java/by/andd3dfx/tree/MirrorTreeTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import by.andd3dfx.tree.MirrorTree.Node;
44
import org.junit.Test;
55

6-
import static by.andd3dfx.tree.MirrorTree.mirror;
76
import static org.assertj.core.api.Assertions.assertThat;
87

98
public class MirrorTreeTest {
@@ -31,7 +30,7 @@ public void testMirror() {
3130
var _5 = new Node(5, _6, _7);
3231
var _4 = new Node(4, _3, _5);
3332

34-
var result = mirror(_4);
33+
var result = MirrorTree.mirror(_4);
3534

3635
assertThat(result).isEqualTo(_4);
3736
check(_4, _5, _3);
@@ -41,6 +40,8 @@ public void testMirror() {
4140
check(_6, _0, _9);
4241
check(_2, _8, null);
4342
check(_1, null, null);
43+
check(_0, null, null);
44+
check(_9, null, null);
4445
check(_8, null, _m2);
4546
}
4647

0 commit comments

Comments
 (0)