Beispiel #1
0
 public CopiableStackEnumerator(CopiableStack stack)
 {
     current = new Node <char>
     {
         Next = stack._first,
     };
 }
Beispiel #2
0
        public static CopiableStack Copy(CopiableStack original)
        {
            var stack = new CopiableStack();

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

            return(stack);
        }
Beispiel #3
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());
        }