The minimum stack data structure ---

The minimum stack

  1. Support push, pop, top operation.
  2. GetMin support operations to O (1) time complexity of obtaining the minimum stack.

A method, dual-stack

Ideas: a normal data storage stack, the stack for another (successive) minimum. push judging newly added elements and the minimum stack size of the top element, if the newly added elements smaller, not only to be pushed to normal stack, but also pushed the minimum stack

; Otherwise only normal stack can be pushed. pop of the time. We have to determine what, if pop the stack elements is the minimum before and, if so, the minimum will also pop up in the minimum stack.

 

Guess you like

Origin www.cnblogs.com/hueralin/p/12007215.html