Esempio n. 1
0
 private void ShiftStacks()
 {
     if (stackOld.IsEmpty())
     {
         while (!stackNew.IsEmpty())
         {
             stackOld.Push(stackNew.Pop());
         }
     }
 }
Esempio n. 2
0
 public int Min()
 {
     if (s2.IsEmpty())
     {
         return(int.MaxValue);
     }
     else
     {
         return(s2.Peek());
     }
 }
Esempio n. 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);
        }