Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9.2 Rewrite the SLList implementation and call the new implementation CircularQueue. You will be deleting a lot of methods from SLList because the CircularQueue

image text in transcribedimage text in transcribed

9.2 Rewrite the SLList implementation and call the new implementation CircularQueue. You will be deleting a lot of methods from SLList because the CircularQueue API is much smaller in comparison: the entire CircularQueue API has four methods described in Table 9.3. Your CircularQueue implementation must meet the following specifications: 1 2 3 4 5 6 7 8 9 Your CircularQueue implementation will use a circular linked list, which is the same as a linked list except that no links are null (that is, no node's next field is ever null) and the value of last.next is first whenever the list is not empty. CircularQueue keeps only one Node instance variable last. > CircularQueue has a private inner class called Node, just like SLList, except that CircularQueue's Node is simpler and is exactly the same as what's shown on lines 5 - 8 below: public class CircularQueue { private Node last; // references the most recently added Node private int n; // number of Nodes in this CircularQueue private class Node { E data; Node next; } 10 11 | // Other methods follow (With this Node class, your addLast and removeFirst methods will have to do the work that was previously done by the Node constructor in SLList. Also note that you will be renaming addLast to enqueue and removeFirst to dequeue.) > All of CircularQueue's public methods are shown in Table 9.3. void E } Table 9.3 CircularQueue API int Method enqueue (E element) dequeue () boolean isEmpty() size() What it does Inserts element as the last element of the Queue Removes and returns the first element of the Queue (the element that has been in the Queue the longest) Returns true if the Queue is empty and false if it isn't Returns the number of items in the list

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

Statistics Unlocking The Power Of Data

Authors: Robin H. Lock, Patti Frazer Lock, Kari Lock Morgan, Eric F. Lock, Dennis F. Lock

1st Edition

0470601876, 978-0470601877

More Books

Students also viewed these Programming questions

Question

Is this really true, or am I just taking it for granted?

Answered: 1 week ago