Write a method called splitStack that accepts a stack of integers as a parameter and rearranges its

Question:

Write a method called splitStack that accepts a stack of integers as a parameter and rearranges its elements so that all the negatives appear on the bottom of the stack and all the nonnegatives appear on the top. If after this method is called you were to pop numbers off the stack, you would first get all the nonnegative numbers and then get all the negative numbers. It does not matter what order the numbers appear in as long as all the negatives appear lower in the stack than all the nonnegatives. For example, if the stack stores [3, −5, 1, 2, −4], an acceptable result from your method would be [−5, −4, 3, 1, 2]. Use a single queue as auxiliary storage.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: