I was having some problem when trying to perform a sort in Java. Here is the reference link that I found: Sorting an array with Stacks and Queues. Basically I am in the same situation as him, just that his is an Integer Queue whereas mine is String ArrayQueue. Here is my sort():
private ArrayQueue<ArrayQueue<E>> Q;
private int n;
public void sort() {
if (Q.size() <= 1) return;
ArrayQueue<E> left = new ArrayQueue<E>(), right = new ArrayQueue<E>();
while (!Q.isEmpty()) {
left.enqueue(Q.dequeue());
if (!Q.isEmpty()) {
right.enqueue(Q.dequeue());
}
}
merge(left, right);
}
For my dequeue(), it is returning E:
public E dequeue() throws ArrayQueueException {
if(f == r){
f = f -1;
r = r -1;
}else
f = f +1;
size --;
return Q[f];
}
As for the enqueue, it is taking E element as parameter:
public void enqueue(E element) throws ArrayQueueException {
//Code
}
The errors are at the left.enqueue and right.enqueue part inside the sort(). Error message as:
The method enqueue(E) in the type ArrayQueue<E> is not applicable for the arguments (ArrayQueue<E>)
I was following the reference link that I found. Any ideas?