Showing posts with label Stack. Show all posts
Showing posts with label Stack. Show all posts

March 14, 2015

Building a Stack with a getMax() function

Building a Stack with a getMax() function
Question:Suppose you had a Stack class. Write a new class MaxStack which, in addition to push() and pop(), has a method getMax() which returns the largest item in the stack. Use your existing Stack class to store the stack’s contents.