Beispiel #1
0
        static void Main()
        {
            MyStack <int> numbers = new MyStack <int>();

            for (int i = 0; i < 20; i++)
            {
                numbers.Push(i);
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Deleted from stack - {0}", numbers.Pop());
            }

            // Display the stack
            foreach (var number in numbers)
            {
                Console.WriteLine(number);
            }

            numbers.Clear();
            try
            {
                Console.WriteLine("Peek at top element: ");
                numbers.Peek();
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            MyStack stack = new MyStack();

            stack.Push(1);
            stack.Push(5);
            stack.Push(8);
            Console.WriteLine($"Count={stack.Count}");
            stack.Pop();
            stack.Push(5);
            stack.Push(8);
            stack.Clear();
            stack.Push(14);
            stack.Push(5);
            stack.Push(8);
            stack.Push(5);
            stack.Push(")");
            stack.Push(")");
            stack.Push(8);
            stack.Pop();
            stack.Pop();
            Console.WriteLine($"Top={stack.Top()}");
            stack.Pop();
        }