Delete the root element from the tree.

This commit is contained in:
Imre Balassa 2018-07-07 01:38:35 +02:00
parent b4969dd2b8
commit 76d17d75a8
3 changed files with 14 additions and 3 deletions

View File

@ -57,7 +57,7 @@ public class BinaryTree {
}
public void delete(int value) {
deleteRecursive(root, value);
root = deleteRecursive(root, value);
}
private Node deleteRecursive(Node current, int value) {

View File

@ -6,7 +6,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class BinaryTreeTest {
public class BinaryTreeUnitTest {
@Test
public void givenABinaryTree_WhenAddingElements_ThenTreeNotEmpty() {
@ -70,6 +70,17 @@ public class BinaryTreeTest {
assertEquals(initialSize, bt.getSize());
}
@Test
public void it_deletes_the_root() {
int value = 12;
BinaryTree bt = new BinaryTree();
bt.add(value);
assertTrue(bt.containsNode(value));
bt.delete(value);
assertFalse(bt.containsNode(value));
}
@Test
public void givenABinaryTree_WhenTraversingInOrder_ThenPrintValues() {

View File

@ -5,7 +5,7 @@ import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class TrieTest {
public class TrieUnitTest {
@Test
public void whenEmptyTrie_thenNoElements() {