예제 #1
0
        public new int Pop()
        {
            int value = base.Pop();

            if (value == Min())
            {
                s2.Pop();
            }
            return(value);
        }
예제 #2
0
 private void ShiftStacks()
 {
     if (stackOld.IsEmpty())
     {
         while (!stackNew.IsEmpty())
         {
             stackOld.Push(stackNew.Pop());
         }
     }
 }
예제 #3
0
        public bool Sort()
        {
            if (stack.IsEmpty())
            {
                return(false);
            }

            while (!stack.IsEmpty())
            {
                int top = stack.Pop();
                while (!tempStack.IsEmpty() && tempStack.Peek() > top)
                {
                    stack.Push(tempStack.Pop());
                }
                tempStack.Push(top);
            }

            while (!tempStack.IsEmpty())
            {
                stack.Push(tempStack.Pop());
            }
            return(true);
        }
예제 #4
0
        public int Pop()
        {
            MyStack <int> last = GetLastStack();

            if (last == null)
            {
                throw new InvalidOperationException();
            }
            int v = last.Pop();

            size--;
            if (size == 0)
            {
                stacks.Remove(last);
            }
            return(v);
        }