static void Main(string[] args)
    {
        Random rnd = new Random();
        OurStack<int> stack = new OurStack<int>();
        for (int i = 0; i < 10; i++)
        {
            stack.Push(rnd.Next(100));
        }
        int initialCount = stack.Count;
        Console.Write("origin numbers:");
        for (int i = 0; i < initialCount; i++)
        {
            Console.Write( stack.Pop() + " ");

        }

        Console.WriteLine();
        for (int i = 0; i < 10; i++)
        {
            stack.Push(rnd.Next(100));
        }

        Console.WriteLine("Show last(peek) : " + stack.Peek());
        Console.WriteLine("Show and remove last :" + stack.Pop() + "\nafter removing tha last one the last is :" + stack.Peek());
    }
        static void Main(string[] args)
        {
            OurStack<int> stack = new OurStack<int>();
            stack.Push(1);
            stack.Push(2);
            stack.Push(5);

            int[] stackToArray = stack.ToArray();
            for (int i = 0; i < stackToArray.Length; i++)
            {
                Console.Write(stackToArray[i] + " ");
            }
            Console.WriteLine();
            Console.WriteLine(stack.Peek());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Peek());
            Console.WriteLine(stack.Contains(0));
            stack.Clear();
            Console.WriteLine(stack.Count);
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Implement the ADT stack as auto-resizable array.");
            Console.WriteLine("Resize the capacity on demand\n");

            OurStack<int> stack = new OurStack<int>();
            stack.Push(12);
            stack.Push(34);
            stack.Push(9);

            int[] stackToArray = stack.ToArray();
            Console.WriteLine("Stack contents: ");
            for (int i = 0; i < stackToArray.Length; i++)
            {
                Console.Write("{0} ", stackToArray[i]);
            }
            Console.WriteLine("\nAfter Peek(): {0}\n", stack.Peek());
            Console.WriteLine("After Pop(): {0}\n", stack.Pop());
            Console.WriteLine("Again Peek(): {0}\n", stack.Peek());
            Console.WriteLine("\nThe stack contains 20? {0}\n", stack.Contains(20));
            stack.Clear();
            Console.WriteLine("Count of the stack after Clear(): {0}\n", stack.Count);
        }
 public OurQueue()
 {
     inbox  = new OurStack();
     outbox = new OurStack();
 }