Implementing ADS AbstractQueue in Queue Class, Essays (high school) of History

Instructions for implementing the abstractqueue interface inside the queue class, focusing on the offer, poll, peek, size, isempty, and contains methods. The offer method adds an element to the end of the queue, while poll removes and returns the first element and checks for empty collections. The peek method returns the front element without removing it. The size and isempty methods return the number of elements and a boolean indicating if the queue is empty, respectively. The contains method checks if an element exists in the queue.

Typology: Essays (high school)

Pre 2010

Uploaded on 10/23/2022

Papayayax
Papayayax 🇻🇳

4.8

(13)

144 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Queue
Your task is to implement the ADS AbstractQueue<E> inside the Queue<E> class provided. You have to
implement all the methods in order to solve the problem, however you are free to add more methods
with any access modifier you want.
void offer (E element)adds an element at the end of the queue and increases the size.
E poll () removes and returns the first element at the queue also decreases the size and performs
a check if this method is called upon empty collection if so throw IllegalStateException with message of
your chose the message itself will not be tested.
E peek () – return the element at the current front of the queue if the collection is empty throw
IllegalStateException with appropriate message.
int size () – returns the number of elements inside the stack.
Boolean isEmpty () – returns if the stack contains any elements or not.
Traverse():
Boolean Contains(E element):
Solution:
Offer(E element)
As you can see a lot of the operations described above are a lot like those we did on the Stack problem
so think how you can reuse and modify those. Now you can see slightly different way of adding the
elements in the stack implementation we had pointer to the top element here we have to the first
pf2

Partial preview of the text

Download Implementing ADS AbstractQueue in Queue Class and more Essays (high school) History in PDF only on Docsity!

Queue

Your task is to implement the ADS AbstractQueue inside the Queue class provided. You have to implement all the methods in order to solve the problem, however you are free to add more methods with any access modifier you want.  void offer (E element) – adds an element at the end of the queue and increases the size.  E poll () – removes and returns the first element at the queue also decreases the size and performs a check if this method is called upon empty collection if so throw IllegalStateException with message of your chose the message itself will not be tested.  E peek () – return the element at the current front of the queue if the collection is empty throw IllegalStateException with appropriate message.  int size () – returns the number of elements inside the stack.  Boolean isEmpty () – returns if the stack contains any elements or not.  Traverse():  Boolean Contains(E element): Solution:  Offer(E element) As you can see a lot of the operations described above are a lot like those we did on the Stack problem so think how you can reuse and modify those. Now you can see slightly different way of adding the elements in the stack implementation we had pointer to the top element here we have to the first

pointer so you need to find the last element so you can offer the new node. The only specific problem here is the poll () method

All of the other methods are really easy and straightforward to be implemented. If it doesn't

work the first time simply try different approach.