Implement a method remove(int data) to remove the first node with given data from a linked list.
Assumptions
-
There is a class Node with two elements:
-
int data
-
Node next
-
-
There is a class LinkedList with a property head pointing to the first element of the linked list. Head may have null if the linked list has no elements. You need to add your new method to this class. You can assume it has all other required methods and works as expected.
-
There is a display method that may look like below:
-
Node current = head;
-
while(current!=null){
-
System.out.println(current.data);
-
current=current.next;
-
}
-
-
- Getters and setters need not be used for data and next for simplicity
-
All these classes are treated to be in a single package for simplicity