Пример #1
0
        //Push element x onto stack.
        public void Push(int x)
        {
            Stack_Node temp = new Stack_Node(x, top);

            this.top = temp;
            count++;
        }
Пример #2
0
        //Removes the element on top of the stack.
        public void Pop()
        {
            Stack_Node temp = this.top;

            this.top = top.GetNext();
            temp.Dispose();
        }
Пример #3
0
        //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);
        }
Пример #4
0
 public Stack_Node(int data, Stack_Node next)
 {
     this.data = data;
     this.next = next;
 }
Пример #5
0
 /** initialize your data structure here. */
 public MinStack()
 {
     count = 0;
     top   = null;
 }