Queue<E> constructor

Queue<E>()

Creates an empty Queue.

A first-in-first-out (FIFO) queue interface implementation, mimicking Java's Queue.

This implementation provides queue operations using a List as the underlying storage. Elements are added to the rear and removed from the front.

Key Features:

  • FIFO ordering: First element added is first to be removed
  • Dynamic sizing: Grows and shrinks as needed
  • List-based: Built on top of a resizable array
  • Efficient operations: Optimized for queue use cases

Usage Examples:

final queue = Queue<String>();

// Add elements to the queue
queue.offer('first');
queue.offer('second');
queue.offer('third');

// Peek at the front element
print(queue.peek()); // 'first'

// Remove elements from the queue
print(queue.poll()); // 'first'
print(queue.poll()); // 'second'

// Check size
print(queue.size()); // 1

// Check if empty
print(queue.isEmpty); // false

Implementation

Queue() : _elements = <E>[];