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(0); }
public void enqueue(E element){ queue.add(element); }
public E peek(){ return queue.get(0); }
}
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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!