Added Zigzag Traversal of a Binary Tree (#3811)

* Added Zigzag Traversal of a Binary Tree

* fixed file name

Co-authored-by: Albina Gimaletdinova <gimaletdinovaalbina@gmail.com>
This commit is contained in:
Albina
2023-01-12 15:06:11 +03:00
committed by GitHub
parent 64181d6ea7
commit 5aa417b6ae
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package com.thealgorithms.datastructures.trees;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Albina Gimaletdinova on 11/01/2023
*/
public class ZigzagTraversalTest {
@Test
public void testRootNull() {
assertEquals(Collections.emptyList(), ZigzagTraversal.traverse(null));
}
@Test
public void testSingleNodeTree() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[]{50});
assertEquals(List.of(List.of(50)), ZigzagTraversal.traverse(root));
}
@Test
public void testZigzagTraversal() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[]{7, 6, 14, 2, 80, 100});
assertEquals(List.of(List.of(7), List.of(14, 6), List.of(2, 80, 100)), ZigzagTraversal.traverse(root));
}
}