Question: Please Complete this java code --------------------------------------------------- public class LinkedListOOOO{ private Node head = null; private Node tail = null; public class Node { Object data;

Please Complete this java code

---------------------------------------------------

public class LinkedListOOOO{ private Node head = null; private Node tail = null; public class Node { Object data; Node next; //Node constructor public Node(Object element) { data = element; next = null; } //Node toString method to print Node element public String toString() { return String.valueOf(this.data); } } public void add(int index, Object element) { /////////////////////////// // Write your code here! // /////////////////////////// // add an element(as a node) at given index } public void addFirst(Object element) { /////////////////////////// // Write your code here! // /////////////////////////// // add an element(as a node) at the first of the list } public void addLast(Object element) { /////////////////////////// // Write your code here! // /////////////////////////// // add an element(as a node) at the last of current list } public Object getFirst() { /////////////////////////// // Write your code here! // /////////////////////////// // Return the element value of first node } public Object getLast() { /////////////////////////// // Write your code here! // /////////////////////////// // Return the element value of first node } public void remove(int index) { /////////////////////////// // Write your code here! // /////////////////////////// // Remove an element(a node) at given index } public Object removeFirst() { /////////////////////////// // Write your code here! // /////////////////////////// // Return the element value of first node // Remove an element(a node) at given index } public Object removeLast() { /////////////////////////// // Write your code here! // /////////////////////////// // Return the element value of first node // Remove an element(a node) at given index } public int size() { /////////////////////////// // Write your code here! // /////////////////////////// // Return how many elements in current list // Don't keep the size value, when size() method called, 

Hint:

Your test program will runs with sentinal loop with user input.

The main menu will be similar as follows.

-------Linked List Test Program------

0 Exit Program

1 Add First Node

2 Add Last Node

3 Add at Index

4 Remove First Node

5 Remove Last Node

6 Remove at Index

7 Print List Size

Select Option: user input here

Except for options 0 and 7 above, when calling a method on the list make sure the method prints the list content before and after executing the called method, For example, the output of testing method removeLast() would be displayed like this

(assuming the list has 10, 20, 30, 40, 50):

Testing method removeLastNode()

List content before removing last node is: 10 20 30 40 50

List content after removing last node is: 10 20 30 40

User choose remove option but there is no element in the List, you need to show the message like this

List is Empty now.

Except for options 0 and 7 above, when calling a method on the list make sure the method prints the list content before and after executing the called method, For example, the output of testing method removeLast() would be displayed like this

(assuming the list has 10, 20, 30, 40, 50):

Testing method removeLastNode()

List content before removing last node is: 10 20 30 40 50

List content after removing last node is: 10 20 30 40

 // retrieve whole list and count the number of element and return it } public String toString() { Node temp = head; String str = "["; while(temp.next != null) { str = str + temp.data + ", "; temp = temp.next; } str = str + temp.data; return str + "]"; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!