//Push element x onto stack. public void Push(int x) { Stack_Node temp = new Stack_Node(x, top); this.top = temp; count++; }
//Removes the element on top of the stack. public void Pop() { Stack_Node temp = this.top; this.top = top.GetNext(); temp.Dispose(); }
//Retrieve the minimum element in the stack. public int GetMin() { int output = this.top.GetData(); Stack_Node temp = this.top; while (temp != null) { if (temp.GetData() < output) { output = temp.GetData(); } temp = temp.GetNext(); } return(output); }
public Stack_Node(int data, Stack_Node next) { this.data = data; this.next = next; }
/** initialize your data structure here. */ public MinStack() { count = 0; top = null; }