Esempio n. 1
0
        public static CopiableStack Copy(CopiableStack original)
        {
            var stack = new CopiableStack();

            foreach (var item in original.Reverse())
            {
                stack.Push(item);
            }

            return(stack);
        }
Esempio n. 2
0
        public static void Start()
        {
            // 定义并初始化堆栈
            var stack = new CopiableStack();

            stack.Push('1');
            stack.Push('2');
            stack.Push('3');

            // 可用性测试

            //var count = stack.Count();
            //Console.WriteLine(count);

            //Console.WriteLine(stack.Pop());
            //Console.WriteLine(stack.Pop());
            //Console.WriteLine(stack.Pop());
            //Console.WriteLine(stack.Pop());

            // 习题
            var copy = CopiableStack.Copy(stack);

            foreach (var item in copy)
            {
                Console.WriteLine(item);
            }

            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine(copy.Pop());
            Console.WriteLine(copy.Pop());
            Console.WriteLine(copy.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
        }