The question is this:
You need to sort a queue in a new member method void sort() you add to the queue.
The rules are:
- You can not use any loops. Only recursion is allowed.
- You can create as many private methods as you wish.
- You may create and use two auxiliary queues of the same kind (call it Queue – has a default constructor).
- You don’t know anything about the internal structure of the queue.
- The only methods given to you are:
bool empty(), Data peek(), Data dequeue(), void enqueue(Data d) dequeue()returns null if the list is empty,enqueue()ignores null inputs.- The sorting order needs to be ascending (front of queue should have the smallest value).
- The comparable value is in integer inside the
Datastructure, calledx.
I know it can be solved. I have yet to find an answer for this. Any ideas would be appreciated.
First of all, thanks for the answers. They pointed me to the right solution. I voted them up to give credit, but since I managed to solve this question, I’ll accept my own answer (at least until a better one comes).
So first of all, the homework was about “Taxies” (you know how homework is…) and a TaxiQueue, in Java.
The solution was:
I hope that other students may find it useful some day!