logo CodeStepByStep logo

reorder

Language/Type: C++ stack queue collections STL
Related Links:

Write a function named reorder that accepts as a parameter a queue of integers that are already sorted by absolute value, and modifies it so that the integers are sorted normally. For example, if a queue variable named q stores the following elements:

front {1, -2, 4, 5, -7, -9, -12, 28, -34} back

Then the call of reorder(q); should modify it to store the following values:

front {-34, -12, -9, -7, -2, 1, 4, 5, 28} back

Constraints: You may use a single stack as auxiliary storage.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.