Stack with Push, Pop, Min and Max functions


Implement a data structure similar to a stack that supports the following operations as efficiently as possible:
  • Push, which adds a new element atop the stack,
  • Pop, which removes the top element of the stack,
  • Find-Max, which returns (but does not remove) the largest element of the stack, and
  • Find-Min, which returns (but does not remove) the smallest element of the stack, and
What would be the fastest implementation of this data structure?

0 comments:

Post a Comment