mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Added threaded binary tree (#6995)
* Add One-Time Pad Cipher implementation in Java * Add One-Time Pad Cipher implementation (fixed) * Add ThreadedBinaryTree with in-order traversal and tests * feat: add threaded binary tree implementation and tests * fix: remove redundant null check for SpotBugs compliance
This commit is contained in:
committed by
GitHub
parent
ac6fef19dc
commit
14c0b0844e
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* TheAlgorithms (https://github.com/TheAlgorithms/Java)
|
||||
* Author: Shewale41
|
||||
* This file is licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package com.thealgorithms.datastructures.trees;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Basic tests for ThreadedBinaryTree inorder traversal.
|
||||
*/
|
||||
public class ThreadedBinaryTreeTest {
|
||||
|
||||
@Test
|
||||
public void testInorderTraversalSimple() {
|
||||
ThreadedBinaryTree tree = new ThreadedBinaryTree();
|
||||
tree.insert(50);
|
||||
tree.insert(30);
|
||||
tree.insert(70);
|
||||
tree.insert(20);
|
||||
tree.insert(40);
|
||||
tree.insert(60);
|
||||
tree.insert(80);
|
||||
|
||||
List<Integer> expected = List.of(20, 30, 40, 50, 60, 70, 80);
|
||||
List<Integer> actual = tree.inorderTraversal();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInorderWithDuplicates() {
|
||||
ThreadedBinaryTree tree = new ThreadedBinaryTree();
|
||||
tree.insert(5);
|
||||
tree.insert(3);
|
||||
tree.insert(7);
|
||||
tree.insert(7); // duplicate
|
||||
tree.insert(2);
|
||||
|
||||
List<Integer> expected = List.of(2, 3, 5, 7, 7);
|
||||
List<Integer> actual = tree.inorderTraversal();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user