Beispiel #1
0
    static void Main(String[] args)
    {
        var stackQueue = new QueueWithTwoStacks <int>();
        int q          = Convert.ToInt32(Console.ReadLine());

        for (int i = 0; i < q; i++)
        {
            string[] a_temp = Console.ReadLine().Split(' ');
            int      type   = Convert.ToInt32(a_temp[0]);
            if (type == 1)
            {
                int x = Convert.ToInt32(a_temp[1]);
                stackQueue.Enqueue(x);
            }
            else if (type == 2)
            {
                stackQueue.Dequeue();
            }
            else
            {
                Console.WriteLine(stackQueue.Peek());
            }
        }

        Console.ReadKey();
    }
Beispiel #2
0
    static void Main(String[] args)
    {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
        var stackQueue = new QueueWithTwoStacks <int>();
        int q          = Convert.ToInt32(Console.ReadLine());

        for (int i = 0; i < q; i++)
        {
            string[] a_temp = Console.ReadLine().Split(' ');
            int      type   = Convert.ToInt32(a_temp[0]);
            if (type == 1)
            {
                int x = Convert.ToInt32(a_temp[1]);
                stackQueue.Enqueue(x);
            }
            else if (type == 2)
            {
                stackQueue.Dequeue();
            }
            else
            {
                Console.WriteLine(stackQueue.Peek());
            }
        }

        Console.ReadKey();
    }
Beispiel #3
0
        public void QueueWithTwoStacksTest()
        {
            var queue = new QueueWithTwoStacks();

            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            Assert.Equal(4, queue.Count);
            Assert.Equal(2, queue.Peek());
            Assert.Equal(2, queue.Dequeue());
            Assert.Equal(3, queue.Dequeue());
            Assert.Equal(4, queue.Peek());
            Assert.Equal(2, queue.Count);
            queue.Enqueue(6);
            Assert.Equal(3, queue.Count);
            Assert.Equal(4, queue.Dequeue());
            Assert.Equal(5, queue.Dequeue());
            Assert.Equal(6, queue.Dequeue());
        }