What would be the datastructure in following scenario? (Stack with maximum)

Posted by Abhishek Jain on Stack Overflow See other posts from Stack Overflow or by Abhishek Jain
Published on 2010-04-10T17:39:55Z Indexed on 2010/05/28 4:21 UTC
Read the original article Hit count: 180

Filed under:
|

Please note that there is no limitation of memory. I need to insert int from 1 to 1000.

I can do the each of the following operations in constant order of time:

  1. push():adds to the top
  2. pop():removes the top element
  3. getMax(): returns the max element

Please suggest me appropriate datastructure.

© Stack Overflow or respective owner

Related posts about homework

Related posts about data-structures