I have a remove method , find the element in that list and delete it.That topic is about Doubly linked list.Is my operation true in if and else if statement for the formation of the new list?
public void Remove(int key) {//key = number in the list.
if (head == null) {
System.out.println("Empty List..!");
} else if (key == head.key) {
head.prev.next = head.next;
head.next = null;
noOfNodes--;
} else if (key == tail.key) {
tail.next.prev = tail.prev;
tail.prev = null;
noOfNodes--;
} else {
for (LinkedListNode temp = head; temp.next != null; temp = temp.next) {
if (temp.key == key) {
temp.prev.next = temp.next;
temp.next.prev = temp.prev;
temp.prev = null;
temp.next = null;
noOfNodes--;
}
}
}
}