Question: You are to create a java.util.Queue using DoublyLinkedList rules in the same project you made for lab 2, follow the diagram. Implement all the methods
- You are to create a java.util.Queue using DoublyLinkedList rules in the same project you made for lab 2, follow the diagram.
- Implement all the methods in the attached diagram.
- Your class LinkedListQueue must inherit the attached AbstractQueue .
- The removeNode(n:Node):void method is a private helper method. it is to make your life easier so when you need to remove a node you don't need to repeat your code over and over. Have in mind this method is for internal use and it takes a Node. It must be able to remove from head, tail, and/or middle. It is used inside of methods: poll, remove(object), and the bonus Iterator::remove
Your tests should not use java.util.LinkedList anymore, it should be replaced with LinkedListQueue.
- If you have done it right and your main variable is of type java.util.Queue, you simply need to change the initialization in the @BeforeEach.
Implement java.util.Iterator in LinkedListQueue by overriding LinkedListQueue::Iterator.
- For full bonus you need to implement remove, next and hasNext.
You need to use the following UML and also AbstarctQueue :
1.UML

2.AbstractQueue.java code:
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import java.util.Queue;
public abstract class AbstractQueue implements Queue {
@Override
public Iterator iterator() {
throw new UnsupportedOperationException( "iterator() is a bonus method, you must override it.");
}
@Override
public Object[] toArray() {
Object[] array = new Object[ size()];
int i = 0;
for ( E r : this) {
array[i++] = r;
}
return array;
}
@SuppressWarnings( "unchecked")
@Override
public T[] toArray( T[] a) {
Objects.requireNonNull( a);
if ( a.length
a = (T[]) new Object[ size()];
int i = 0;
for ( E r : this) {
a[i++] = (T) r;
}
return a;
}
@Override
public boolean addAll( Collection c) {
Objects.requireNonNull( c);
for ( E r : c) {
add( r);
}
return true;
}
@Override
public boolean containsAll( Collection c) {
for ( Object o : c) {
if ( !contains( o))
return false;
}
return true;
}
@Override
public boolean removeAll( Collection c) {
for ( Object o : c) {
remove( o);
}
return true;
}
@Override
public boolean retainAll( Collection c) {
Iterator it = iterator();
while ( it.hasNext()) {
if ( !c.contains( it.next()))
it.remove();
}
return true;
}
@Override
public boolean add( E e) {
return offer( e);
}
@Override
public E remove() {
return poll();
}
@Override
public E element() {
return peek();
}
}
Lab - Queue datastructure java queue JE Abstractoueue A
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
