Question: Write a class called GenDoubleLinkedList which is a generic double linked list. Used the DoubleLinkedListTester.java on bottom (DO NOT MODIFY THE DRIVER!) and write the
Write a class called GenDoubleLinkedList which is a generic double linked list. Used the DoubleLinkedListTester.java on bottom (DO NOT MODIFY THE DRIVER!) and write the following classes:
The class GenDoubleLinkedList needs to have the following:
- Internal class ListNode which has
-- Instance Variables
--- data of type T
--- nextLink of type ListNode
--- prevLink of type ListNode
-- Constructors
--- Default
--- Parameterized
- Instance Variables
-- head of type ListNode which always points to the beginning of the linked list
-- current of type ListNode which moves around pointing to one of the nodes
- Constructor
-- A default constructor that initializes head to an empty ListNode and sets current to point at the head.
- Methods
-- goToNext This moves the current node forward in the list by one node. It doesnt move forward if that node is null
-- goToPrev This moves the current node backwards in the list by one node. It doesnt move backwards if that node is null.
-- getDataAtCurrent returns the data at the current node as long as the current isnt null
-- setDataAtCurrent takes in a parameter and sets the data at the current node to that value as long as current is not null
-- insertNodeAfterCurrent creates a new node based on data that is passed in by a parameter and puts that node after the current position
-- deleteCurrentNode removes the current node from the list by resetting the links
-- showList prints out the contents of the list line-by-line
-- inList returns a true or false value based on whether or not the data passed in via a parameter is in the list
You should check for all possible edge cases: if all the methods from this driver work, it does not necessarily mean they work for all possible cases. You need to cover them.
public class DoubleLinkedListTester {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Double Linked List Tester");
System.out.println("Create, insert, and move test");
GenDoubleLinkedList
dList.setDataAtCurrent("1");
dList.insertNodeAfterCurrent("2");
dList.goToNext();
dList.insertNodeAfterCurrent("3");
dList.goToNext();
dList.insertNodeAfterCurrent("4");
dList.goToNext();
dList.showList();
System.out.println("Previous and Deletion Test");
dList.goToPrev();
dList.deleteCurrentNode();
dList.showList();
System.out.println("In list test");
System.out.println(dList.inList("2"));
System.out.println(dList.inList("3"));
System.out.println("Test Done");
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
