Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the implementation of ADT queue in Java (NOTED IN CODE): public class ListQueue implements MyQueue { private class Node { T item; // public

Complete the implementation of ADT queue in Java (NOTED IN CODE):

public class ListQueue implements MyQueue { private class Node { T item; // public Node next; // null } private Node head = null; private Node tail = null; private int size = 0; /** * is empty? */ public boolean isEmpty() { // your implementation here: return true; } /** * @return the number of items in the queue */ public int size() { // your implementation here: return 0; } /** * enqueue: add an element at the tail of queue */ public void enqueue(T item) { // your implementation here: } /** * dequeue: remove and return the head of the queue * @return the deleted value * @throws NoSuchElementException if queue is empty */ public T dequeue() { // your implementation here: return null; } /** * peek: view the head of queue without removing it. * @return Null if queue is empty */ public T peek() { // your implementation here: return null; } }

TEST code

public class Driver{

public static void main(String[] args) { MyQueue q; boolean useList = false; // make it false if you want to array implementation if (useList) q = new ListQueue(); // default setting: use a list to implement the queue. You can change it. else q = new ArrayQueue(); for(int i = 0; i < 1000; i++) // add a large number of items onto the queue { q.enqueue(i); } System.out.println("Now, dequeue items!"); while(!q.isEmpty()) { System.out.print(q.dequeue() + " "); } System.out.println(" End of dequeueing"); // you should fully test/debug all methods!

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions