We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2b83b31 commit 7eb0785Copy full SHA for 7eb0785
DataStructures/Lists/DoublyLinkedList.java
@@ -116,8 +116,13 @@ public Link deleteTail() {
116
public void delete(int x) {
117
Link current = head;
118
119
- while (current.value != x) // Find the position to delete
120
- current = current.next;
+ while (current.value != x) {// Find the position to delete
+ if (current != tail) {
121
+ current = current.next;
122
+ } else {// If we reach the tail and the element is still not found
123
+ throw new RuntimeException("The element to be deleted does not exist!");
124
+ }
125
126
127
if (current == head)
128
deleteHead();
0 commit comments