Write a method called maxToTop that takes a stack of integers as a parameter and moves the
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 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.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Question Posted: