Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started