Question: Question 2 ( 7 0 % ) : Create a class DoublyLinkedList to implement a doubly linked list and implement the following functions: 1 .

Question 2(70%):
Create a class DoublyLinkedList to implement a doubly linked list and implement the following functions:
1. printList(): This function prints all elements in the linked list.
2. addFirst(E e): This function adds a new node with element e at the front of a linked list.
3. addLast(E e): This function adds a new node with element e at the end of a linked list.
4. deleteFirst(): This function deletes a node at the front of a linked list. The function returns the deleted nodes element.
5. deleteLast(): This function deletes a node at the end of a linked list. The function returns the deleted nodes element.
Create two lists in the main function with the following data:
List 1: 10,4,518,20
List 1 should be created using addFirst(E e) and then the items in the list should be printed. For this list, show the operation of deleteFirst() to delete the first element and print the list again.
List2: Apple,Banana,Cherry,Grape,Orange
List 2 should be created using addLast(E e) and then the items in the list should be printed. For this list, show the operation of deleteLast() to delete the last element and print the list again.
Insert your Java code in the box below. Also, submit the java code.

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!