Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var stack = new CustomStack <int>();

            var cmdArgs = Console.ReadLine()
                          .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

            while (cmdArgs[0] != "END")
            {
                switch (cmdArgs[0])
                {
                case "Push":
                    var elements = cmdArgs.Skip(1).Select(int.Parse);
                    stack.Push(elements);
                    break;

                case "Pop":
                    try
                    {
                        stack.Pop();
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }

                    break;

                default:
                    break;
                }

                cmdArgs = Console.ReadLine()
                          .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            }

            PrintStack(stack);
            PrintStack(stack);
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            var customStack = new CustomStack <int>();

            customStack.Push(1);
            customStack.Push(2);
            customStack.Push(3);
            customStack.Push(4);
            customStack.Push(5);
            customStack.Push(6);
            customStack.Push(7);
            customStack.Push(8);


            //var stack = new Stack<int>();
            //var peak = stack.Peek();
            //Console.WriteLine(peak);
            var peak = customStack.Peak();

            Console.WriteLine(peak);
            Console.WriteLine();
            customStack.Foreach(x => Console.Write(x + " "));
        }