Enqueue values at the back and dequeue them from the front in first-in, first-out order.

Algorithm

Basic Implementation

basic.cs
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static string Render(List<int> values) => string.Join(" -> ", values);
    static void Main() {
        var queue = new Queue<int>();
        foreach (var value in new[] {10, 20, 30}) queue.Enqueue(value);
        var removed = new List<int>();
        while (queue.Count > 0) removed.Add(queue.Dequeue());
        Console.WriteLine(Render(removed));
    }
}

The queue keeps the oldest value at the front and adds new values at the back.

Step 1 - Enqueue 10, 20, 30

New values join at the back. The oldest value, 10, stays at the front.

Queue after three enqueues: front 10, then 20, then back 30.nextnext10front2030back

Step 2 - Dequeue removes 10

Removing from the front returns 10 and makes 20 the new front.

After one dequeue: removed is 10; front moves to 20.next10removed20front30back

Complexity

  • Time: O(1) per operation with a real queue
  • Space: O(n)

Implementation notes

  • Queue<int> is the BCL FIFO container; its managed backing storage grows as needed and is reclaimed by GC. Calling Dequeue() on an empty queue would throw, so the implementation guards removal with queue.Count > 0.
  • The removed values are collected in a List<int> only for deterministic rendering; the replay still shows the actual enqueue/dequeue state changes rather than jumping straight to the final a -> b -> c string.
front The front is the oldest value still waiting in the queue.
FIFO A queue removes values in first-in, first-out order.