Question: Consider the following ArrayList implementation of a queue: public class ArrayListQueue { private ArrayList queue; public ArrayListQueue ( ) { queue = new ArrayList (
Consider the following ArrayList implementation of a queue:
public class ArrayListQueue
private ArrayList queue;
public ArrayListQueue queue new ArrayList;
public E dequeue return queue.remove;
public void enqueueE element queue.addelement;
public E peek return queue.get;
Why is this implementation inefficient? Would the complexity have been better if we had made the front of the queue be at the end of the ArrayList and the rear of the queue be at the front of the ArrayList?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
