Question: please help me. were using java attach the code text and a screenshot . Do not forget comments please Write a method called expunge that
please help me. were using java attach the code text and a screenshot . Do not forget comments please
Write a method called expunge that accepts a stack of integers as a parameter and makes sure that the stacks elements are in nondecreasing order from top to bottom, by removing from the stack any element that is smaller than any element(s) on top of it. For example, if the stack stores [4, 20, 15, 15, 8, 5, 7, 12, 3, 10, 5, 1], the element values 3, 7, 5, 8, and 4 should be removed because each has an element above it with a larger value. So your method should change the stack to store [20, 15, 15, 12, 10, 5, 1]. Notice that now the elements are in nondecreasing order from top to bottom. If the stack is empty or has just one element, nothing changes. Use one queue or stack (but not both) as auxiliary storage.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
