Question: Write a method called maxToTop that takes a stack of integers as a parameter and moves the largest value in the stack to the top
Write a method called maxToTop that takes a stack of integers as a parameter and moves the largest value in the stack to the top of the stack, leaving all other values in their original order. You may assume that the stack does not contain any duplicates. For example, if a stack s stores [27, 5, 42, -11, 0, 19] , the call of maxToTop(s) should change it to store [27, 5, -11, 0, 19, 42] . If the stack is empty, your method should not change it. Use one queue as auxiliary storage.
Step by Step Solution
3.30 Rating (156 Votes )
There are 3 Steps involved in it
public static void maxToTop Stack stack if stackisEmpty Laget return ... View full answer
Get step-by-step solutions from verified subject matter experts
