Question: Write a method called reorder that accepts a queue of integers as a parameter and that puts the integers into sorted (nondecreasing) order, assuming that
Write a method called reorder that accepts a queue of integers as a parameter and that puts the integers into sorted (nondecreasing) order, assuming that the queue is already sorted by absolute value. For example, if the queue stores [1, 2, −2, 4, −5, 8, −8, 12, −15], notice that the values appear in sorted order if you ignore the sign of the numbers. Your method should reorder the values so that the queue stores [−15, −8, −5, −2, 1, 2, 4, 8, 12]. Use one stack as auxiliary storage.
Step by Step Solution
3.29 Rating (190 Votes )
There are 3 Steps involved in it
publi... View full answer
Get step-by-step solutions from verified subject matter experts
