()
| 35 | } |
| 36 | |
| 37 | func (this *MinStack) Pop() { |
| 38 | if this.top == nil { |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | if this.top == this.min { |
| 43 | if this.top.next == nil { |
| 44 | this.min = nil |
| 45 | this.top = nil |
| 46 | } else { |
| 47 | this.top = this.top.next |
| 48 | this.min = this.top |
| 49 | |
| 50 | minPtr := this.min |
| 51 | for minPtr != nil { |
| 52 | if minPtr.val < this.min.val { |
| 53 | this.min = minPtr |
| 54 | } |
| 55 | minPtr = minPtr.next |
| 56 | } |
| 57 | } |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | this.top = this.top.next |
| 62 | } |
| 63 | |
| 64 | func (this *MinStack) Top() int { |
| 65 | return this.top.val |
no outgoing calls