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

  1. You are to create a java.util.Queue using DoublyLinkedList rules in the same project you made for lab 2, follow the diagram.
  2. Implement all the methods in the attached diagram.
    1. Your class LinkedListQueue must inherit the attached AbstractQueue .
    2. 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.

  1. 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.

  1. For full bonus you need to implement remove, next and hasNext.

You need to use the following UML and also AbstarctQueue :

1.UML

 You are to create a java.util.Queue using DoublyLinkedList rules in the

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 -tail: Nodec -size:int +offer:R): boolean +poll):R peek): ): void + terator): Ierator> lang -Node(value: T) -Node(next : Node, prev:Node) -Node(value: T, next : Node prev: Node oString: String prev Lab - Queue datastructure java queue JE Abstractoueue A -tail: Nodec -size:int +offer:R): boolean +poll):R peek): ): void + terator): Ierator> lang -Node(value: T) -Node(next : Node, prev:Node) -Node(value: T, next : Node prev: Node oString: String prev

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!