sorting a queue
ok I know...I have already posted about sorting a linked list, and as anon said it would be better to use sort() to do this rather doing it yourself, it was a good practice though
How about sorting a queue. I was told that it is a possible interview question...How would you do it. I am not asking for code just some clues. I understand that I cannot use iterators to move through the queue. Am I to use only front and but??? But after that? How can I refer to a middle element in the queue?Can I refer to a middle element?
I think that is the point of a queue. It is a container adaptor that represents the idea that you put things in at one end and they come out of the second end in the same order. Therefore it doesn't make sense to sort it.
If you want them to come out of the other end in sorted order, you could use a priority_queue.
Edit: and if you really want a sortable queue, then you might use a deque, which allows you to pop_front and push_back efficiently.