Delete the root element from the tree.
This commit is contained in:
parent
b4969dd2b8
commit
76d17d75a8
@ -57,7 +57,7 @@ public class BinaryTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete(int value) {
|
public void delete(int value) {
|
||||||
deleteRecursive(root, value);
|
root = deleteRecursive(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node deleteRecursive(Node current, int value) {
|
private Node deleteRecursive(Node current, int value) {
|
||||||
|
@ -6,7 +6,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class BinaryTreeTest {
|
public class BinaryTreeUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenABinaryTree_WhenAddingElements_ThenTreeNotEmpty() {
|
public void givenABinaryTree_WhenAddingElements_ThenTreeNotEmpty() {
|
||||||
@ -70,6 +70,17 @@ public class BinaryTreeTest {
|
|||||||
assertEquals(initialSize, bt.getSize());
|
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
|
@Test
|
||||||
public void givenABinaryTree_WhenTraversingInOrder_ThenPrintValues() {
|
public void givenABinaryTree_WhenTraversingInOrder_ThenPrintValues() {
|
||||||
|
|
@ -5,7 +5,7 @@ import org.junit.Test;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class TrieTest {
|
public class TrieUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenEmptyTrie_thenNoElements() {
|
public void whenEmptyTrie_thenNoElements() {
|
Loading…
x
Reference in New Issue
Block a user