logo CodeStepByStep logo

splitStack

Language/Type: Java Stack Queue collections
Related Links:

Write a method named splitStack that accepts as a parameter 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 method 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, ArrayLists, etc.) other than a single Queue of integers.

Type your Java solution code here:


This is a method exercise. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.