/// <summary> /// Internal method to move elements within the two internal stacks. /// </summary> private void MoveStack() { // If there are no items in the oldest item stack, move any items // from the newest item stack. if (StackOldestQueue.Count == 0) { while (StackNewestQueue.Count != 0) { StackOldestQueue.Push(StackNewestQueue.Pop()); } } }
/// <summary> /// Gets the first item in the queue w/o removing it. If there are no items in the queue, throws an exception. /// </summary> /// <returns>The item.</returns> public T Peek() { // Check for empty queue. if (Count == 0) { throw new InvalidOperationException(); } // Init temporary stack & copy to it. MoveStack(); // Pop for temp stack. return(StackOldestQueue.Peek()); }