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.
Can someone please let me know, how I can implement this requirement. I will be really thankful.
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.
Thank you so much Nathan. It worked as expected. :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.