Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Queue; import java.util.NoSuchElementException; //Class for a simple queue based on SimpleList //The front of the queue should be the front of //the list. //READ

import java.util.Queue; import java.util.NoSuchElementException;

//Class for a simple queue based on SimpleList //The "front" of the queue should be the front of //the list.

//READ THE DOCUMENTATION for the Queue interface for more information //on how these methods should work and when exceptions should //be thrown. This data structure does not allow adding null.

//DO NOT re-implement nodes in this class... remember how //inheritance works in Java and make use of that! class SimpleQueue extends SimpleList implements Queue { public boolean add(T item) { //O(1) return false; } public boolean offer(T item) { //O(1) return false; }

public T remove() { //O(1) return null; }

public T poll() { //O(1) return null; } public T element() { //O(1) return null; } public T peek() { //O(1) return null; } //------------------------------------------------------------- // Main Method For Your Testing -- Edit all you want //------------------------------------------------------------- public static void main(String[] args){ SimpleQueue nums = new SimpleQueue<>(); nums.offer(2); nums.offer(3); nums.offer(5); if (nums.peek() == 2 && nums.size()==3){ System.out.println("Yay 1"); } if (nums.poll() == 2 && nums.poll() == 3 && nums.poll() == 5 && nums.poll() == null){ System.out.println("Yay 2"); } } }

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions