public void Method2_Implement_Queue_Using_Stack_DeQueueIsCostlyAtFirstTime(int[] arr) { /* MUCH MORE FASTER! * Complexity Analysis: * Time Complexity: * Push operation : O(1). * Same as pop operation in stack. * Pop operation : O(N). * The difference from above method1 is that in this method element is returned and all elements are restored back in a single call. * Auxiliary Space: O(N). * Use of stack for storing values. */ var Queue = new StackQueue <int>(); foreach (var item in arr) { Queue.EnQueue2(item); } for (int i = 0; i < arr.Length; i++) { var data = Queue.DeQueue2(); Assert.Equal(arr[i], data); output.WriteLine(data.ToString()); } }