示例#1
0
        public static void Main(string[] args)
        {
            //			Implement stack and Queue using array as backing field in the class
            MyStack stack = new MyStack();
            stack.push (1);
            stack.push (2);
            stack.push (3);
            stack.push (4);
            Console.WriteLine ("The top element is " + stack.peek ());
            Console.WriteLine ("The popped element is " + stack.pop ());
            Console.WriteLine ("The popped element is " + stack.pop ());
            Console.WriteLine ("The top element is " + stack.peek ());
            MyQueue queue = new MyQueue();
            queue.enqueue (1);
            queue.enqueue (2);
            queue.enqueue (3);
            queue.enqueue (4);

            Console.WriteLine ("The dequeued element is " + queue.dequeue ());
            Console.WriteLine ("The dequeued element is " + queue.dequeue ());
        }
示例#2
0
        public static void Main(string[] args)
        {
//			Implement stack and Queue using array as backing field in the class
            MyStack stack = new MyStack();

            stack.push(1);
            stack.push(2);
            stack.push(3);
            stack.push(4);
            Console.WriteLine("The top element is " + stack.peek());
            Console.WriteLine("The popped element is " + stack.pop());
            Console.WriteLine("The popped element is " + stack.pop());
            Console.WriteLine("The top element is " + stack.peek());
            MyQueue queue = new MyQueue();

            queue.enqueue(1);
            queue.enqueue(2);
            queue.enqueue(3);
            queue.enqueue(4);

            Console.WriteLine("The dequeued element is " + queue.dequeue());
            Console.WriteLine("The dequeued element is " + queue.dequeue());
        }