mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-14 17:32:35 +08:00
Revert "Fix for Issue #773. Deleting an element that doesn't exist causes NPE"
This reverts commit 7eb07850733333726ba94bd2c15fc4d22d728759.
This commit is contained in:
@ -116,13 +116,8 @@ public class DoublyLinkedList {
|
||||
public void delete(int x) {
|
||||
Link current = head;
|
||||
|
||||
while (current.value != x) {// Find the position to delete
|
||||
if (current != tail) {
|
||||
current = current.next;
|
||||
} else {// If we reach the tail and the element is still not found
|
||||
throw new RuntimeException("The element to be deleted does not exist!");
|
||||
}
|
||||
}
|
||||
while (current.value != x) // Find the position to delete
|
||||
current = current.next;
|
||||
|
||||
if (current == head)
|
||||
deleteHead();
|
||||
|
Reference in New Issue
Block a user