Esempio n. 1
0
        public void Method1_Implement_Queue_Using_Stack_EnQueueIsCostly(int[] arr)
        {
            /*
             * Complexity Analysis:
             *  Time Complexity:
             *  Push operation: O(1).
             *  Same as pop operation in stack.
             *  Pop operation: O(N).
             *  In the worst case we have empty whole of stack 1 into stack 2
             *  Auxiliary Space: O(N).
             *  Use of stack for storing values.
             */
            var Queue = new StackQueue <int>();

            foreach (var item in arr)
            {
                Queue.EnQueue1(item);
            }

            for (int i = 0; i < arr.Length; i++)
            {
                var data = Queue.DeQueue1();
                Assert.Equal(arr[i], data);
                output.WriteLine(data.ToString());
            }
        }