Can you make a driver program for the DoublyLinkedList given bellow, how the output of the driver should look like will be attached bellow. public class DoublyLinkedList { private static class Node { private E element; private Node prev; private Node next; public Node(E e, Node p, Node n) { element = e; prev = p; next = n; } public E getElement() { return element; } public Node getPrev() { return prev; } public Node getNext() { return next; } public void setPrev(Node p) { prev = p; } public void setNext(Node n) { next = n; } } private Node header; private Node trailer; private int size = 0; public DoublyLinkedList() { header = new Node<>(null, null, null); trailer = new Node<>(null, header, null); header.setNext(trailer); } public int size() { return size; } public boolean isEmpty() { return size == 0; } public E first() { if (isEmpty()) return null; return header.getNext().getElement(); } public E last() { if (isEmpty()) return null; return trailer.getPrev().getElement(); } public void addFirst(E e) { addBetween(e, header, header.getNext()); } public void addLast(E e) { addBetween(e, trailer.getPrev(), trailer); } public E removeFirst() { if (isEmpty()) return null; return remove(header.getNext()); } public E removeLast() { if (isEmpty()) return null; return remove(trailer.getPrev()); } private void addBetween(E e, Node predecessor, Node successor) { Node newest = new Node<>(e, predecessor, successor); predecessor.setNext(newest); successor.setPrev(newest); size++; } private E remove(Node node) { Node predecessor = node.getPrev(); Node successor = node.getNext(); predecessor.setNext(successor); successor.setPrev(predecessor); size--; return node.getElement(); } public String toString() { StringBuilder sb = new StringBuilder("("); Node walk = header.getNext(); while (walk != trailer) { sb.append(walk.getElement()); walk = walk.getNext(); if (walk != trailer) sb.append(", "); } sb.append(")"); return sb.toString(); } }

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
100%

Can you make a driver program for the DoublyLinkedList given bellow, how the output of the driver should look like will be attached bellow.

public class DoublyLinkedList<E> {
private static class Node<E> {
private E element;
private Node<E> prev;
private Node<E> next;
public Node(E e, Node<E> p, Node<E> n) {
element = e;
prev = p;
next = n;
}
public E getElement() { return element; }
public Node<E> getPrev() { return prev; }
public Node<E> getNext() { return next; }
public void setPrev(Node<E> p) { prev = p; }
public void setNext(Node<E> n) { next = n; }
}
private Node<E> header;
private Node<E> trailer;
private int size = 0;
public DoublyLinkedList() {
header = new Node<>(null, null, null);
trailer = new Node<>(null, header, null);
header.setNext(trailer);
}
public int size() { return size; }
public boolean isEmpty() { return size == 0; }
public E first() {
if (isEmpty()) return null;
return header.getNext().getElement();
}
public E last() {
if (isEmpty()) return null;
return trailer.getPrev().getElement();
}
public void addFirst(E e) {
addBetween(e, header, header.getNext());
}
public void addLast(E e) {
addBetween(e, trailer.getPrev(), trailer);
}
public E removeFirst() {
if (isEmpty()) return null;
return remove(header.getNext());
}
public E removeLast() {
if (isEmpty()) return null;
return remove(trailer.getPrev());
}
private void addBetween(E e, Node<E> predecessor, Node<E> successor) {
Node<E> newest = new Node<>(e, predecessor, successor);
predecessor.setNext(newest);
successor.setPrev(newest);
size++;
}
private E remove(Node<E> node) {
Node<E> predecessor = node.getPrev();
Node<E> successor = node.getNext();
predecessor.setNext(successor);
successor.setPrev(predecessor);
size--;
return node.getElement();
}
public String toString() {
StringBuilder sb = new StringBuilder("(");
Node<E> walk = header.getNext();
while (walk != trailer) {
sb.append(walk.getElement());
walk = walk.getNext();
if (walk != trailer)
sb.append(", ");
}
sb.append(")");
return sb.toString();
}
}

The output of the driver file should look something like this:

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: CSC281 Current: CSC202 Tail: csc202 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.
Head: CSC282 Current: COM110 Tail: MTH166 5 items
CSc202
ENG211
Csc202
COM110
MTH166
Transcribed Image Text: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: CSC281 Current: CSC202 Tail: csc202 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. Head: CSC282 Current: COM110 Tail: MTH166 5 items CSc202 ENG211 Csc202 COM110 MTH166
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Linked List Representation
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