示例#1
0
        public static void Main()
        {
            var currentStack = new Stack <string>();

            StackAdd(currentStack);

            var stack = new StackOfStrings(currentStack);

            while (true)
            {
                var input = Console.ReadLine()
                            .ToLower()
                            .Split()
                            .ToArray();
                string command = input[0];

                if (command.Equals("end"))
                {
                    Environment.Exit(0);
                }
                dynamic result = string.Empty;

                switch (command)
                {
                case "push":
                    string inputData = input[1];
                    stack.Push(inputData);
                    break;

                case "pop":
                    result = stack.Pop();
                    break;

                case "peek":
                    result = stack.Peek();
                    break;

                case "isempty":
                    result = stack.IsEmpty();
                    break;

                default:
                    result = "unrecognized command";
                    break;
                }

                Console.WriteLine(result);
            }
        }
        static void Main(string[] args)
        {
            StackOfStrings stackOf = new StackOfStrings();

            for (int i = 0; i < 10; i++)
            {
                stackOf.Push(i.ToString());
            }
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(stackOf.Peek());
            }
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(stackOf.Pop());
            }
        }