Hello All,

I want to write a c++ code to sort a queue with the help of another queue and a non array element. Please help me getting the code.

Re: Need C++ code to sort a queue using another queue and non array alement 80 80

Can someone please let me know, how I can implement this requirement. I will be really thankful.

Re: Need C++ code to sort a queue using another queue and non array alement 80 80

Well a queue is a FIFO data structure. In order to sort it you need to to find the smallest part by popping the front and checking it against a min variable. Then if it is not smaller push it back on the back of the queue. Do that until you go all the way through the queue and you should have the smallest element in the queue. add it to the builder queue and remove it from the unsorted queue. Then you go through the queue again and find the smallest element. Then you add that to the builder queue and remove it from the unsorted queue. Keep doing that until the starting queue is empty.

Re: Need C++ code to sort a queue using another queue and non array alement 80 80

Thank you so much Nathan. It worked as expected. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.