Question: public interface LinkedList { /** * @return This method returns the head of the list */ Node getHead(); /** * @return This method returns the
public interface LinkedList { /** * @return This method returns the head of the list */ Node getHead(); /** * @return This method returns the number of elements stored in this list * */ int getCount(); /** * @return This method returns the node at the given index * */ Node get(int index) throws IndexOutOfBoundsException; /** * This method should set the value at the given location * @param index the index of the location where the new value to be set * @param newValue the new value * @return the old value at the index * @throws IndexOutOfBoundsException Throws the exception when the index is out of bound */ String set(int index, String newValue); /** * This method should add the given value to the end of the list * @param value This is the value to be added */ void append(String value); /** * This method should insert the given value after the given node. * (We assume that the given node is in the list.) * * @param node This is the node after which the value should be inserted * @param value This is the value to be inserted */ void insertAfter(Node node, String value) throws IllegalArgumentException; /** * This method should remove the given node in the list * (We assume that the given node is in the list.) * * All the values stored at/after the given index should be shifted forward by one index * For example, if the array has 3 elements stored at index 0, index 1, index 2 * if we remove the element at index 0, the elements at index 1 and index 2 should be moved to index 0 and index 1 * @param node the node to be removed * @return the value of the removed node */ String remove(Node node) throws IllegalArgumentException; } public class SinglyLinkedList implements LinkedList { private SinglyLinkedListNode head; // the reference that points to the first node; is NULL if the list is empty private int count; // the count of the elements that the list stores /** * DO NOT change this method */ @Override public SinglyLinkedListNode getHead(){ return this.head; } /** * the class to represent Node in the list * DO NOT change this inner class * */ public static class SinglyLinkedListNode extends Node{ SinglyLinkedListNode next; public SinglyLinkedListNode(String value) { super(value); this.next = null; } @Override public SinglyLinkedListNode getNext(){ return this.next; } } /** * DO NOT change this constructor * This constructor initialize the instance variables */ public SinglyLinkedList(){ this.count = 0; this.head = null; } /** * DO NOT change this method * @return This method returns the current number of elements stored in this list * */ @Override public int getCount() {return this.count;} /* Todo: implement this method */ @Override public Node get(int index) throws IndexOutOfBoundsException { } /* Todo: implement this method */ @Override public String set(int index, String newValue) { } /* Todo: implement this method */ @Override public void append(String value) { } /* Todo: implement this method */ @Override public void insertAfter(Node node, String value) throws IllegalArgumentException { } /* Todo: implement this method */ @Override public String remove(Node node) throws IllegalArgumentException { } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
