Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76d17d7

Browse filesBrowse files
author
Imre Balassa
committed
Delete the root element from the tree.
1 parent b4969dd commit 76d17d7
Copy full SHA for 76d17d7

File tree

Expand file treeCollapse file tree

3 files changed

+14
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-3
lines changed
Open diff view settings
Collapse file

‎data-structures/src/main/java/com/baeldung/tree/BinaryTree.java‎

Copy file name to clipboardExpand all lines: data-structures/src/main/java/com/baeldung/tree/BinaryTree.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private boolean containsNodeRecursive(Node current, int value) {
5757
}
5858

5959
public void delete(int value) {
60-
deleteRecursive(root, value);
60+
root = deleteRecursive(root, value);
6161
}
6262

6363
private Node deleteRecursive(Node current, int value) {
Collapse file

‎…va/com/baeldung/tree/BinaryTreeTest.java‎ ‎…om/baeldung/tree/BinaryTreeUnitTest.java‎data-structures/src/test/java/com/baeldung/tree/BinaryTreeTest.java renamed to data-structures/src/test/java/com/baeldung/tree/BinaryTreeUnitTest.java data-structures/src/test/java/com/baeldung/tree/BinaryTreeTest.java renamed to data-structures/src/test/java/com/baeldung/tree/BinaryTreeUnitTest.java

Copy file name to clipboardExpand all lines: data-structures/src/test/java/com/baeldung/tree/BinaryTreeUnitTest.java
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import org.junit.Test;
88

9-
public class BinaryTreeTest {
9+
public class BinaryTreeUnitTest {
1010

1111
@Test
1212
public void givenABinaryTree_WhenAddingElements_ThenTreeNotEmpty() {
@@ -70,6 +70,17 @@ public void givenABinaryTree_WhenDeletingNonExistingElement_ThenTreeDoesNotDelet
7070
assertEquals(initialSize, bt.getSize());
7171
}
7272

73+
@Test
74+
public void it_deletes_the_root() {
75+
int value = 12;
76+
BinaryTree bt = new BinaryTree();
77+
bt.add(value);
78+
79+
assertTrue(bt.containsNode(value));
80+
bt.delete(value);
81+
assertFalse(bt.containsNode(value));
82+
}
83+
7384
@Test
7485
public void givenABinaryTree_WhenTraversingInOrder_ThenPrintValues() {
7586

Collapse file

‎…est/java/com/baeldung/trie/TrieTest.java‎ ‎…java/com/baeldung/trie/TrieUnitTest.java‎data-structures/src/test/java/com/baeldung/trie/TrieTest.java renamed to data-structures/src/test/java/com/baeldung/trie/TrieUnitTest.java data-structures/src/test/java/com/baeldung/trie/TrieTest.java renamed to data-structures/src/test/java/com/baeldung/trie/TrieUnitTest.java

Copy file name to clipboardExpand all lines: data-structures/src/test/java/com/baeldung/trie/TrieUnitTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import static org.junit.Assert.assertFalse;
66
import static org.junit.Assert.assertTrue;
77

8-
public class TrieTest {
8+
public class TrieUnitTest {
99

1010
@Test
1111
public void whenEmptyTrie_thenNoElements() {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.