Question
Test contains(), indexOf(), and toArray methods. Linked Queue Code: import exceptions.ArrayCapacityException; import exceptions.EmptyCollectionException; import support.LNode; public class LinkedQueue implements QueueADT { private LNode front; private
Test contains(), indexOf(), and toArray methods.
Linked Queue Code:
import exceptions.ArrayCapacityException; import exceptions.EmptyCollectionException; import support.LNode;
public class LinkedQueue
private LNode
public LinkedQueue() { front = null; rear = null; size = 0; }
@Override public void enqueue(T element) { // TODO Auto-generated method stub
LNode
@Override public T dequeue() { // TODO Auto-generated method stub T retData; if (isEmpty()) { throw new EmptyCollectionException("linked queue"); } else {
retData = front.getData(); front = front.getNext(); size--; return retData; } }
@Override public T first() { // TODO Auto-generated method stub if (isEmpty()) { throw new EmptyCollectionException("linked queue"); } else {
return front.getData(); } }
@Override public boolean isEmpty() { // TODO Auto-generated method stub return (size == 0); }
public boolean contains(T elem) { LNode @Override public int size() { // TODO Auto-generated method stub return size; } public String toString() { String retString = "["; LNode } QueueTester Code: public class QueueTester { public static void main(String[] args) { //test both queues //LinkedQueue System.out.println("Dequeue [4]: " + lq.dequeue()); System.out.println("First [5]: " + lq.first()); System.out.println("Queue [5 6 7]: " + lq); System.out.println("Dequeue [5]: " + lq.dequeue()); System.out.println("First [6]: " + lq.first()); System.out.println("Queue [6 7]: " + lq); lq.enqueue(8); lq.enqueue(9); System.out.println("Queue [6 7 8 9]: " + lq); } }
Step 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