Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement Linked Lists In this assignment, you will implement the singly linked list and doubly linked list. Please download the following files to start the
Implement Linked Lists In this assignment, you will implement the singly linked list and doubly linked list. Please download the following files to start the assignment: Node.java put it in the package: main.java Linked List.java put it in the package: main.java SinglyLinkedList.java put it in the package: main.java DoublyLinkedList.java put it in the package: main.java Test files: RandomNames.txt put it in the package: test.resources Linked ListTest.java put it in the package: test.java The Linked ListTest.java is updated on Thursday, 1/28/2021. Step 1. Set up tests for SinglyLinkedList In the LinkedListTest.java, at line 22, change static ListType listType = ListType.Doubly; to static ListType listType = ListType. Singly; Step 2. Implement SinglyLinkedList.java so that all the tests pass Step 3. Submit SinglyLinkedList.java package main.java; public abstract class Node { private String value; = newValue;} public String getValue() {return value;} public void setValue(String newValue) {this.value public Node(String value) { this.value = value; } public abstract Node getNext(); } package main.java; 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 o, index 1, index 2 * if we remove the element at index o, the elements at index 1 and index 2 should be moved to index and index 1 * @param node the node to be removed @return the value of the removed node String remove(Node node) throws IllegalArgumentException; } package main.java; 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 Illega LargumentException { /* Todo: implement this method */ @Override public String remove(Node node) throws Illega LargumentException { } } package main.java; 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 { } } Damarion Maynard Catherine Wolfe Luciana Stone Ace Stephenson Alana Walls Jacoby Pace Avah Gallagher Hudson Lyons Addison Coffey Jasper Mcfarland Elian Nicholson Gunner Haney Chloe Stephens Harrison Jarvis Mateo Barrera Cristina Abbott Jacey Hebert Drew Jacobs Emilee Bird Donna Massey Kamron Schaefer Kiara Alexander Kamari Mcintosh Salvador Mccarty Karma White Madden Kim Nehemiah Glover Justice Briggs Adrien Merritt Ansley Wade Damarion Maynard Catherine Wolfe Luciana Stone Ace Stephenson Alana Walls Jacoby Pace Avah Gallagher Hudson Lyons Addison Coffey Jasper Mcfarland Elian Nicholson Gunner Haney Chloe Stephens Harrison Jarvis Mateo Barrera Cristina Abbott Jacey Hebert Drew Jacobs Emilee Bird Donna Massey Kamron Schaefer Kiara Alex der Kamari Mcintosh Salvador Mccarty Karma White Madden Kim Nehemiah Glover Justice Briggs Adrien Merritt Ansley Wade Implement Linked Lists In this assignment, you will implement the singly linked list and doubly linked list. Please download the following files to start the assignment: Node.java put it in the package: main.java Linked List.java put it in the package: main.java SinglyLinkedList.java put it in the package: main.java DoublyLinkedList.java put it in the package: main.java Test files: RandomNames.txt put it in the package: test.resources Linked ListTest.java put it in the package: test.java The Linked ListTest.java is updated on Thursday, 1/28/2021. Step 1. Set up tests for SinglyLinkedList In the LinkedListTest.java, at line 22, change static ListType listType = ListType.Doubly; to static ListType listType = ListType. Singly; Step 2. Implement SinglyLinkedList.java so that all the tests pass Step 3. Submit SinglyLinkedList.java package main.java; public abstract class Node { private String value; = newValue;} public String getValue() {return value;} public void setValue(String newValue) {this.value public Node(String value) { this.value = value; } public abstract Node getNext(); } package main.java; 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 o, index 1, index 2 * if we remove the element at index o, the elements at index 1 and index 2 should be moved to index and index 1 * @param node the node to be removed @return the value of the removed node String remove(Node node) throws IllegalArgumentException; } package main.java; 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 Illega LargumentException { /* Todo: implement this method */ @Override public String remove(Node node) throws Illega LargumentException { } } package main.java; 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 { } } Damarion Maynard Catherine Wolfe Luciana Stone Ace Stephenson Alana Walls Jacoby Pace Avah Gallagher Hudson Lyons Addison Coffey Jasper Mcfarland Elian Nicholson Gunner Haney Chloe Stephens Harrison Jarvis Mateo Barrera Cristina Abbott Jacey Hebert Drew Jacobs Emilee Bird Donna Massey Kamron Schaefer Kiara Alexander Kamari Mcintosh Salvador Mccarty Karma White Madden Kim Nehemiah Glover Justice Briggs Adrien Merritt Ansley Wade Damarion Maynard Catherine Wolfe Luciana Stone Ace Stephenson Alana Walls Jacoby Pace Avah Gallagher Hudson Lyons Addison Coffey Jasper Mcfarland Elian Nicholson Gunner Haney Chloe Stephens Harrison Jarvis Mateo Barrera Cristina Abbott Jacey Hebert Drew Jacobs Emilee Bird Donna Massey Kamron Schaefer Kiara Alex der Kamari Mcintosh Salvador Mccarty Karma White Madden Kim Nehemiah Glover Justice Briggs Adrien Merritt Ansley Wade
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started