Write a method called removeMin that accepts a stack of integers as a parameter and removes and

Question:

Write a method called removeMin that accepts a stack of integers as a parameter and removes and returns the smallest value from the stack. For example, if the stack stores [2, 8, 3, 19, 2, 3, 2, 7, 12, −8, 4], your method should remove and return −8, leaving the stack storing [2, 8, 3, 19, 2, 3, 2, 7, 12, 4] . If the minimum value appears more than once, all occurrences of it should be removed. For example, given the same stack, if we again call removeMin on it, the method would return 2 and leave the stack storing [8, 3, 19, 3, 7, 12, 4]. Use one 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: