PLEASE SOLVE IN JAVA. I can only fit the entire problem by having the driver code as an image but since there's a picture limit also I had to trim the output so it would nearly fit. THANK YOU IN ADVANCE      public class DoublyLinkedList { // define ListNode elements specific for this type of list, indicating current, previous and next // consider head as name for previous node, and tail for the next one. private ListNode head; private ListNode current; private ListNode tail; // default constructor public DoublyLinkedList() { //*** Task #1: implement a default constructor here, initializing the nodes to null } // method that calculates the length of the list public int length() { //*** Task #2: implement the method navigating through the list until you run out of elements } // method that adds a node at the beginning of the list public void addANodeToStart(E addData) { //*** Task #3: implement this method, taking into consideration that the head will be replaced by a new node. You may want to use a temporary variable } // accessor method that gets data at current node public E getDataAtCurrent() { //*** Task #4: implement this method making sure to take into account the situation when // there current doesn't point to any data (is null) } // method that sets the current node in the beginning, reseting the iteration public void resetIteration() { //*** Task #5: implement the body of the method } // method that checks if there is more to interate in the list public boolean moreToIterate() { //*** Task #6: implement the body of the method } // method that moves the node to the next position, if possible public void goToNext() { //*** Task #7: implement the method taking into account the situation when the list is empty // check if there are other instances when the move is not possible. } // method that resets the reverse iteration, setting the current node to the last one public void resetIterationReverse() { //*** Task #8: implement the body of the method } // method that facilitates the move in the reverse directions, redirecting the node to previous public void goToPrevious() { //*** Task #9: implement this method in a similar way the goToNext() method // make sure to have the right links for the reverse navigations } /* Method that inserts node with newData after the current node. Note: The current node is the same after invocation as it is before invocation. Should not be used with an empty list. Should not be used when the current node has iterated past the entire list. */ public void insertNodeAfterCurrent(E newData) { //*** Task #10: implement this method, making sure to observe the ideas noted above } /* Method that deletes the current node. After the invocation, the current node is the node after the deleted node or null if there is no next node. */ public void deleteCurrentNode() { //*** Task #11: implement this method, making sure to observe the ideas noted above } // method that deletes the head node. public void deleteHeadNode() { //*** Task #12: implement this method } // Searches list for element containing target data. // If target is found, current is set to point at it, // and the function returns true. // If target is not found, current is set to null // and the function returns false. public boolean findInList(E target) { //*** Task #13: implement this method, making sure to observe the ideas noted above } public boolean onList(E target) { //*** Task #14: implement this method } private ListNode Find(E target) { //*** Task #15: implement this method } // meethod that displays the list public void showList() { //*** Task #16: irrespective of navigation through the list, the display remains the same // start from the head and move through the list to show all elements. } // Method useful during testing and debugging, that allows control over the nodes. public void showListState() { System.out.println("Head: " + (head == null ? "null" : head.data) + " Current: " + (current == null ? "null" : current.data) + " Tail: " + (tail == null ? "null" : tail.data) + " " + length() + " items"); }   // inner class for ListNode public class ListNode { // instance variables private E data; private ListNode link; private ListNode previous; // constructor - default public ListNode() { //*** Task #17: implement this constructor } // constructor, fully defining the list public ListNode(E newData, ListNode linkValue, ListNode previousValue) { //*** Task #18: implement this constructor } // mutator for data public void setData(E newData) { //*** Task #19: implement this method } // accessor for data public E getData() { //*** Task #20: implement this method } // mutator for the node public void setLink(ListNode newLink) { //*** Task #21: implement this method } // mutator for the previous node public void setPrevious(ListNode newPrevious) { //*** Task #22: implement this method } // accessor for the current node public ListNode getLink() { //*** Task #23: implement this method } // accessor for the previous node public ListNode getPrevious() { //*** Task #24: implement this method } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

PLEASE SOLVE IN JAVA. I can only fit the entire problem by having the driver code as an image but since there's a picture limit also I had to trim the output so it would nearly fit. THANK YOU IN ADVANCE 

 

 

public class DoublyLinkedList<E>
{
// define ListNode elements specific for this type of list, indicating current, previous and next
// consider head as name for previous node, and tail for the next one.
private ListNode<E> head;
private ListNode<E> current;
private ListNode<E> tail;

// default constructor
public DoublyLinkedList()
{
//*** Task #1: implement a default constructor here, initializing the nodes to null

}

// method that calculates the length of the list
public int length()
{
//*** Task #2: implement the method navigating through the list until you run out of elements

}

// method that adds a node at the beginning of the list
public void addANodeToStart(E addData)
{
//*** Task #3: implement this method, taking into consideration that the head will be replaced by a new node. You may want to use a temporary variable

}

// accessor method that gets data at current node
public E getDataAtCurrent()
{
//*** Task #4: implement this method making sure to take into account the situation when
// there current doesn't point to any data (is null)

}

// method that sets the current node in the beginning, reseting the iteration
public void resetIteration()
{
//*** Task #5: implement the body of the method
}

// method that checks if there is more to interate in the list
public boolean moreToIterate()
{
//*** Task #6: implement the body of the method
}

// method that moves the node to the next position, if possible
public void goToNext()
{
//*** Task #7: implement the method taking into account the situation when the list is empty
// check if there are other instances when the move is not possible.

}

// method that resets the reverse iteration, setting the current node to the last one
public void resetIterationReverse()
{
//*** Task #8: implement the body of the method
}

// method that facilitates the move in the reverse directions, redirecting the node to previous
public void goToPrevious()
{
//*** Task #9: implement this method in a similar way the goToNext() method
// make sure to have the right links for the reverse navigations
}

/*
Method that inserts node with newData after the current node.
Note: The current node is the same after invocation as it is before invocation.
Should not be used with an empty list.
Should not be used when the current node has iterated past the entire list.
*/
public void insertNodeAfterCurrent(E newData)
{
//*** Task #10: implement this method, making sure to observe the ideas noted above
}

/*
Method that deletes the current node. After the invocation,
the current node is the node after the
deleted node or null if there is no next node.
*/
public void deleteCurrentNode()
{
//*** Task #11: implement this method, making sure to observe the ideas noted above
}

// method that deletes the head node.
public void deleteHeadNode()
{
//*** Task #12: implement this method

}

// Searches list for element containing target data.
// If target is found, current is set to point at it,
// and the function returns true.
// If target is not found, current is set to null
// and the function returns false.
public boolean findInList(E target)
{
//*** Task #13: implement this method, making sure to observe the ideas noted above

}

public boolean onList(E target)
{
//*** Task #14: implement this method
}

private ListNode<E> Find(E target)
{
//*** Task #15: implement this method
}

// meethod that displays the list
public void showList()
{
//*** Task #16: irrespective of navigation through the list, the display remains the same
// start from the head and move through the list to show all elements.
}

// Method useful during testing and debugging, that allows control over the nodes.
public void showListState()
{
System.out.println("Head: " + (head == null ? "null" : head.data)
+ " Current: " + (current == null ? "null" : current.data)
+ " Tail: " + (tail == null ? "null" : tail.data)
+ " " + length() + " items");
}

 

// inner class for ListNode
public class ListNode<E>
{
// instance variables
private E data;
private ListNode<E> link;
private ListNode<E> previous;
// constructor - default
public ListNode()
{
//*** Task #17: implement this constructor
}
// constructor, fully defining the list
public ListNode(E newData, ListNode<E> linkValue, ListNode<E> previousValue)
{
//*** Task #18: implement this constructor
}
// mutator for data
public void setData(E newData)
{
//*** Task #19: implement this method
}
// accessor for data
public E getData()
{
//*** Task #20: implement this method
}
// mutator for the node
public void setLink(ListNode<E> newLink)
{
//*** Task #21: implement this method
}
// mutator for the previous node
public void setPrevious(ListNode<E> newPrevious)
{
//*** Task #22: implement this method
}
// accessor for the current node
public ListNode<E> getLink()
{
//*** Task #23: implement this method
}
// accessor for the previous node
public ListNode<E> getPrevious()
{
//*** Task #24: implement this method
}
}
}

Your Tasks
1. Write a class definition for a doubly linked list using a data type of your choice. I would suggest String as the type. If you have a class
that you have already built, such as Student, for one of the guided assignments, feel free to use it.
2. A major task is to modify the Node class to fit the definition of doubly list, and make it as an inner class.
3. You need to build the DoublyLinkedList class. Download the assignment template, DoublyLinkedList.txt, and modify it to work with
your data type. This file contains the lists of tasks you need to perform in order to create an operational class for doubly lists.
• DoublyLinkedList.bxt a
4. You have the freedom to choose the methods you need to navigate through this type of list. You can also use the driver template file,
DoublyLinkedListDriver.txt.
• DoublyLinkedListDriver.txt
5. Here is a list of the operations as the guidance for what is expected for the driver file.
• Define the doubly list with the type of your choice. If you want to use a custom type, such as Student, make sure to include the
class defining the type.
• Add a node to an empty list
• Add at least two nodes to the end of the list
• Add at least one node in the middle of the list
• Delete the first node
• Add two more nodes at the end of the list
• Navigate to the previous node in the list
• Delete from the middle of the list
• Add at the beginning of the list
• Find an element in the list (one that you know is in the list)
• Find an element in the list (one that you know is no more in the list)
• Display the list at the end of all operations
6. Make sure to display the list after each operation.
7. If you implement all the required methods properly, the driver program should generate outputs similar to the following samples. You
are seeing the sample output option 1 below. There are two other options for your reference.
(Sample Output Option 2 e | Sample Output Option 3 e)
Head: null Current: null Tail: null e items
Add a node to an empty list.
Head: CSC201 Current: null Tail: csc201 1 items
Add nodes to the end of the list.
Head: CSC201 Current: CSC201 Tail: CSC202 2 items
Head: CSC201 Current: csc202 Tail: CSC202 3 items
CSc201
csc202
csc202
Add node to the middle of the list.
Head: Csc201 Current: CSC202 Tail: Csc2e2 3 items
Head: CSC201 Current: CSC202 Tail: CSC202 4 items
Csc201
CSc202
ENG211
csc202
Delete the first node.
Csc202
ENG211
CSc202
Add more nodes to end of list.
Transcribed Image Text:Your Tasks 1. Write a class definition for a doubly linked list using a data type of your choice. I would suggest String as the type. If you have a class that you have already built, such as Student, for one of the guided assignments, feel free to use it. 2. A major task is to modify the Node class to fit the definition of doubly list, and make it as an inner class. 3. You need to build the DoublyLinkedList class. Download the assignment template, DoublyLinkedList.txt, and modify it to work with your data type. This file contains the lists of tasks you need to perform in order to create an operational class for doubly lists. • DoublyLinkedList.bxt a 4. You have the freedom to choose the methods you need to navigate through this type of list. You can also use the driver template file, DoublyLinkedListDriver.txt. • DoublyLinkedListDriver.txt 5. Here is a list of the operations as the guidance for what is expected for the driver file. • Define the doubly list with the type of your choice. If you want to use a custom type, such as Student, make sure to include the class defining the type. • Add a node to an empty list • Add at least two nodes to the end of the list • Add at least one node in the middle of the list • Delete the first node • Add two more nodes at the end of the list • Navigate to the previous node in the list • Delete from the middle of the list • Add at the beginning of the list • Find an element in the list (one that you know is in the list) • Find an element in the list (one that you know is no more in the list) • Display the list at the end of all operations 6. Make sure to display the list after each operation. 7. If you implement all the required methods properly, the driver program should generate outputs similar to the following samples. You are seeing the sample output option 1 below. There are two other options for your reference. (Sample Output Option 2 e | Sample Output Option 3 e) Head: null Current: null Tail: null e items Add a node to an empty list. Head: CSC201 Current: null Tail: csc201 1 items Add nodes to the end of the list. Head: CSC201 Current: CSC201 Tail: CSC202 2 items Head: CSC201 Current: csc202 Tail: CSC202 3 items CSc201 csc202 csc202 Add node to the middle of the list. Head: Csc201 Current: CSC202 Tail: Csc2e2 3 items Head: CSC201 Current: CSC202 Tail: CSC202 4 items Csc201 CSc202 ENG211 csc202 Delete the first node. Csc202 ENG211 CSc202 Add more nodes to end of list.
public class DriverDoublyLinkedList_Framework
{
public static void main(String[] args)
{
//*** Task #1: define variables you need for application
//*** Task #2: instantiate new doubly-linked list
//*** Task #3: display state of list, making sure to format it nicely
//*** Task #4: build your list, with a number of elements, by adding nodes, // such as:
//*** Task #5: Add a node to an empty list.
//*** Task #6: Add nodes to the end of the list.
//*** Task #7: Add nodes to the middle of the list.
// see here a sample of set of actions to perform in order
// to show the outcome of that particular set of actions
System.out.println("Add node to the middle of the list.");
list.resetIteration();
list.goToNext();
list.showlistState();
list.insertNodeAfterCurrent ("ENG211");
list.showlistState();
list.showlist();
System.out.println();
System.out.println("=:
====");
/*** Task #8: Continue with other operations to demonstrate the
//*** Task #9: way doubly linked list works
//*** Task #11: delete the first node
//*** Task #12: add more nodes to the end of list
//*** Task #13: delete from the middle of the list
//*** Task #14: add in the beginning of the list
//*** Task #15: iterate to the end of list
//*** Task #16: iterate list in reverse.");
//*** Task #17: delete from the end of the list.
//*** Task #18: find element that should still be in the list
//*** Task #19: find element that should not be in the list anymore
//*** Task #20: display the final list
NOTE:
* the list of operations required above is just a framework
* if you feel the need, play more by adding and removing nodes
*/
{
}
Transcribed Image Text:public class DriverDoublyLinkedList_Framework { public static void main(String[] args) { //*** Task #1: define variables you need for application //*** Task #2: instantiate new doubly-linked list //*** Task #3: display state of list, making sure to format it nicely //*** Task #4: build your list, with a number of elements, by adding nodes, // such as: //*** Task #5: Add a node to an empty list. //*** Task #6: Add nodes to the end of the list. //*** Task #7: Add nodes to the middle of the list. // see here a sample of set of actions to perform in order // to show the outcome of that particular set of actions System.out.println("Add node to the middle of the list."); list.resetIteration(); list.goToNext(); list.showlistState(); list.insertNodeAfterCurrent ("ENG211"); list.showlistState(); list.showlist(); System.out.println(); System.out.println("=: ===="); /*** Task #8: Continue with other operations to demonstrate the //*** Task #9: way doubly linked list works //*** Task #11: delete the first node //*** Task #12: add more nodes to the end of list //*** Task #13: delete from the middle of the list //*** Task #14: add in the beginning of the list //*** Task #15: iterate to the end of list //*** Task #16: iterate list in reverse."); //*** Task #17: delete from the end of the list. //*** Task #18: find element that should still be in the list //*** Task #19: find element that should not be in the list anymore //*** Task #20: display the final list NOTE: * the list of operations required above is just a framework * if you feel the need, play more by adding and removing nodes */ { }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education