Stack And Queue : Stack « Data Structure « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;

    class StackAndQueue
    {
        static void Main()
        {
            Queue<int> queue = new Queue<int>();
            Stack<int> stack = new Stack<int>();

            for (int i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
                stack.Push(i);
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Stack:{0} Queue:{1}",
                                   stack.Pop(), queue.Dequeue());
            }
        }
    }








11.39.Stack
11.39.1.Push and pop value
11.39.2.Clear a stack
11.39.3.Pop and Peek
11.39.4.Stack And Queue
11.39.5.Stack and Queue are both ICollection