Question: //**************************** DLLNode.java ******************************* // node of generic doubly linked list class public class DLLNode { public T info; public DLLNode next, prev; public DLLNode() {

//**************************** DLLNode.java ******************************* // node of generic doubly linked list class

public class DLLNode { public T info; public DLLNode next, prev; public DLLNode() { next = null; prev = null; } public DLLNode(T el) { info = el; next = null; prev = null; } public DLLNode(T el, DLLNode n, DLLNode p) { info = el; next = n; prev = p; } }

//**************************** DLL.java ******************************* // generic doubly linked list class

public class DLL { private DLLNode head, tail; public DLL() { head = tail = null; } public boolean isEmpty() { return head == null; } public void setToNull() { head = tail = null; } public T firstEl() { if (head != null) return head.info; else return null; } public void addToHead(T el) { if (head != null) { head = new DLLNode(el,head,null); head.next.prev = head; } else head = tail = new DLLNode(el); } public void addToTail(T el) { if (tail != null) { tail = new DLLNode(el,null,tail); tail.prev.next = tail; } else head = tail = new DLLNode(el); } public T deleteFromHead() { if (isEmpty()) return null; T el = head.info; if (head == tail) // if only one node on the list; head = tail = null; else { // if more than one node in the list; head = head.next; head.prev = null; } return el; } public T deleteFromTail() { if (isEmpty()) return null; T el = tail.info; if (head == tail) // if only one node on the list; head = tail = null; else { // if more than one node in the list; tail = tail.prev; tail.next = null; } return el; } public void printAll() { for (DLLNode tmp = head; tmp != null; tmp = tmp.next) System.out.print(tmp.info + " "); } public T find(T el) { DLLNode tmp; for (tmp = head; tmp != null && !tmp.info.equals(el); tmp = tmp.next); if (tmp == null) return null; else return tmp.info; } }

public class DLLTest {

public static void main(String[] args) {

DLL test = new DLL();

for(int i = 0; i

test.addToTail("a" + i);

test.printAll();

}

}

//**************************** DLLNode.java ******************************* // node of generic doubly linked list class public

Question IID) Doubly linked lists (30 pts): Download, compile and execute the programs related to Doubly linked lists. (class DLL) Then add the following methods to the class DLL T.java: (a) public void printReverse () that prints the elements of list in reverse. (b)public void deletelth(i) which deletes the ith element from the list. Note that if you reach the end then you have to reverse the direction of counting. In the main0 method of the test class, create a randomly generated Doubly-Linked list of 10 Integers. Next, call the deletelth(7) method and print the lists iteratively until the list becomes empty. Make sure to print the list after each deletion For example, your list initially could be [3 125 879 0]. After deleting 7th element: [3 125872 0][3 125870] After deleting 7th element again; [3 125870]->[312587] After deleting 7th element again (counting in the same direction, then moving reverse), 3 12587]13 125 7] 3 1257315 7]

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!