logo CodeStepByStep logo

You are working on problem set: Week 2 Section ( Pause)

splitStack

Language/Type: C++ Stack Queue collections
Related Links:

Write a function named splitStack that accepts as a parameter a reference to a Stack of integers, and re-orders it so that all the non-negative numbers are at the top in the reverse of their original relative order, and all the negative numbers are at the bottom in the reverse of their original relative order. For example, if passed the stack {4, 0, -1, 5, -6, -3, 2, 7}, your function should modify the stack to store {-3, -6, -1, 7, 2, 5, 0, 4}.

Constraints: Do not declare any auxiliary data structures (e.g. arrays, Grids, Vectors, etc.) other than a single Queue of integers.

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? .

If something seems wrong with our site, please

Is there a problem? Contact us.