tags:

views:

138

answers:

1

How can I sort a queue of size N, using just another queue of size N, and a finite number of variables?

the naïve implementation - finding the minimum of the queue and pushing it to the empty queue, then finding the new minimal and pushing it, etc. is O(n^2). is there a more efficient algorithm?

+1  A: 

Try Merge Sort, which is O(n log n)

Tuomas Pelkonen
Thanks, but Merge Sort takes more space than I have..
BS James