Question: Assume that we have two class ArrayBasedQueue as follows. Note: we do not have any other method for this class. This is supposed to be
Assume that we have two class ArrayBasedQueue as follows. Note: we do not have any other method for this class. This is supposed to be the implementation of ADT Queue. Write two methods enqueue() and dequeue() for class ArrayBasedQueue to add and remove items from the Queue. What is the time complexity of each method? it is in java
This is the signature: public void enqueue(AnyType x);
public AnyType dequeue();
Note: this class is supposed to implement Queue using circular array. We do not need to implement expand(). (just assume we never have more than 1000 items in the queue)
public class ArrayBasedQueue {
private static int MAX_SIZE = 1000; // initial array size
private AnyType[] items; // array to keep items in the queue
private int front; // indicates the index of front in queue
private int count; // the number of items in queue
public ArrayBasedQueue(){
items = (AnyType []) new Object[MAX_SIZE];
front = 0;
count = 0;
}
public int size() {return count;}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
