Esempio n. 1
0
 public static void SortedInsert(LinkedListStack stack, int value)
 {
     if (stack.Size() == 0 || value > stack.Peek())
     {
         stack.Push(value);
     }
     else
     {
         var temp = stack.Pop();
         SortedInsert(stack, value);
         stack.Push(temp);
     }
 }
Esempio n. 2
0
        public int Remove()
        {
            if (stack1.Size() == 0 && stack2.Size() == 0)
            {
                throw new InvalidOperationException("Queue is empty");
            }

            int value;

            if (stack2.Size() > 0)
            {
                return(stack2.Pop());
            }

            while (stack1.Size() > 0)
            {
                value = stack1.Pop();
                stack2.Push(value);
            }
            return(stack2.Pop());
        }
Esempio n. 3
0
 public void Add(int value)
 {
     stack1.Push(value);
 }