Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your second task is to implement a linked queue class in java. We know that array-based queues have a fixed capacity, which might be an

Your second task is to implement a linked queue class in java. We know that array-based queues have a fixed capacity, which might be an issue if we don't know the number of elements that are going to be stored in the queue when instantiating it. In this task, we will address this limitation by using a singly linked list of array queues. Each array in the linked list will have a capacity of eight. When the queue is empty, the linked list is empty. As objects are placed into the queue, they are placed into the arrays that will be stored in the linked list. As necessary, additional arrays are added to the linked list. For example, suppose we begin with an empty queue and then enqueue six times and dequeue once.

The LinkedArrayQueue class has three member variables:

  • A generic singly linked list which will hold references to generic arrays as elements,
  • Two integers front and back.

LinkedArrayQueue must implement the following methods:

  • LinkedArrayQueue() -- the default constructor. Creates an empty singly linked list
  • size() -- returns how many elements are stored in the queue over all arrays.
  • numArrays() -- returns the number of arrays or in other words the number of nodes in the linked list
  • isEmpty() -- tests whether the LinkedArrayQueue is empty.
  • first() -- returns the element at the front of the queue. return null if empty.
  • last() -- returns the element at the back of the queue. return null if empty.
  • enqueue(E e) -- add e to the back of the queue as explained above.
  • dequeue() -- remove the element at the front of the queue and return it. return null if empty. follow the instructions given above, when an array becomes empty.

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

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions