Question: All this is done in Java. So we have to edit a singly linked list and have to add the GET and SET methods so

All this is done in Java. So we have to edit a singly linked list and have to add the GET and SET methods so far I have tried the get method only but I get: "The value at location 2 is: DHSingleLinkedList$Node@1175e2db" from the driver. The get part from my driver method is

 Object value = list.get(2); System.out.println("The value at location 2 is: " + value); 

Here is the get method that I wrote:

public E get(int index) { int n = 0; if (n > size) { return null; } Node node = head; for (int i = 0;i < n; i++) { node = node.next; } return (E) node.next; }

Most of the methods are already created the only thing needed is get and set but I need help fixing my get method so far.

public void add(int index, E item); public E remove(int index); public E get(int index); public E set(int index, E newValue); public int size();

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!