Question
public class DoublyLinkedList { 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
public class DoublyLinkedList
private Node
private Node
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() // to return the first element
{
if (isEmpty())
return null;
return header.getNext().getElement();
}
public E last() // to return the last element
{
if (isEmpty())
return null;
return trailer.getPrev().getElement();
}
public void addBetween(E e, Node
{
Employee e1;
Node
predecessor.setNext(newest);
successor.setPrev(newest);
size++;
}
public E remove(Node
{
if(size==0)
return null;
Node
Node
predecessor.setNext(successor);
successor.setPrev(predecessor);
size--;
return e.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;
else
return remove(header.getNext());
}
public E removeLast()
{
if(isEmpty())
return null;
else
return remove(trailer.getPrev());
}
public void displayForward()
{
for (Node
System.out.println(t.getElement());
}
public void reverse()
{
Node
Node
while (i.getNext()!=j && i!=j)
{
E t=i.getElement();
i.setElement(j.getElement());
j.setElement(t);
i=i.getNext();
j=j.getPrev();
}
}
public void displayBackward()
{
for (Node
System.out.println(t.getElement());
}
public void concat(DoublyLinkedList newList)
{
trailer.getPrev().setNext(newList.header.getNext());
newList.header.getNext().setPrev(trailer.getNext());
trailer=newList.trailer;
}
public static class Node
private E element;
private Node
private Node
public Node(E e,Node
{
element=e;
prev=p;
next=n;
}
public E getElement()
{
return element;
}
public void setElement(E e)
{
element=e;
}
public Node
{
return prev;
}
public Node
{
return next;
}
public void setPrev(Node
{
prev=n;
}
public void setNext(Node
{
next=n;
}
}
}
Add a new class called Employee that has three private attributes called id (int), name (String) Salary (Double). Add the setter and getter for all the data members. Import the class DoublyLinkedList.java covered in Lab-06 Add a new class called AppTest, create as many objects as you want different amount of Salaries. Using the method public void addBetween(E e, NodeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started