mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
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:
@ -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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user