Question: package LinkedList; class DoublyLinkedList { //Initially, heade and tail is set to null Node head, tail; public DoublyLinkedList(){ head = null; tail = null; }

package LinkedList; class DoublyLinkedList { //Initially, heade and tail is set to

package LinkedList;

class DoublyLinkedList {

//Initially, heade and tail is set to null

Node head, tail;

public DoublyLinkedList(){

head = null;

tail = null;

}

//add a node to the list

public void addNode(int item) {

/*

* Your Codes Here

*/

}

void deleteNode(int num) throws ItemNotFoundException {

/*

* Your Codes Here

*/

}

public String toString() {

/*

* Your Codes Here

*/

}

//A node class for doubly linked list

private class Node{

/*

* Your Codes Here

*/

}

}

package LinkedList;

public class DriverDLL {

public static void main(String[] args) throws ItemNotFoundException{

//create a DoublyLinkedList object

DoublyLinkedList dl_List = new DoublyLinkedList();

//Add nodes to the list

dl_List.addNode(10);

dl_List.addNode(20);

dl_List.addNode(30);

dl_List.addNode(40);

dl_List.addNode(50);

dl_List.deleteNode(10);

dl_List.deleteNode(40);

dl_List.deleteNode(30);

// to check the exception:

dl_List.deleteNode(25);

//print the nodes of DoublyLinkedList

System.out.println(dl_List);

}

}

package LinkedList;

public class ItemNotFoundException extends Exception{

/*

* Your Codes Here

*/

}

Create a doubly linked list for storing integers. In doubly liked lists, each node has a connection to its previous and next node. The first node is known as the head (the previous for the head is null), and the last node is known as the tail (the next for the tail is null) Your linked list should have the following properties: 1. No need to say that you must create a node inner class in the beginning. 2. addNode ability: it gets an integer and adds it to the end of the list 3. remove node ability: it gets an integer, finds the integer in the linked list, and removes it from the chain. (note that in 1 and 2, you need to break and establish new previous and next connections, and the process for head and tail might be different from a regular node) 4. In the removal process, if the mentioned integer is not stored in any node, your program should throw an exception called ItemNotFoundException with the message: "Entered number is not in the list" You must create an exception class and do all necessary coding related to this design. (No need to handle the exception) 5. ToString method should print the integers in the linked list if it's not empty and a message if it is empty. Examples are shown below. Nodes of doubly linked list: 2050 Doubly linked list is empty Exception in thread "main" LinkedList.ItemNotFoundException Create breakpoint : Entered number is not in the list at LinkedList.DoublyLinkedList.deleteNode (DoublyLinkedList.java:39) at LinkedList.DriverDLL.main (DriverDLL. java:19)

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!