LinkedQueue<E> constructor

LinkedQueue<E>([
  1. E? defaultValue
])

Creates an empty LinkedQueue.

A queue implementation using a linked list structure, mimicking Java's LinkedList as Queue.

This implementation provides efficient queue operations with constant-time insertion and removal at both ends. It uses a doubly-linked list internally for optimal performance.

Key Features:

  • Constant-time operations: O(1) for offer, poll, peek
  • Memory efficient: Only allocates nodes as needed
  • Unbounded: Can grow to any size (limited by available memory)
  • FIFO ordering: First element added is first to be removed

Usage Examples:

final queue = LinkedQueue<String>();

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

// Process elements in FIFO order
while (!queue.isEmpty) {
  print(queue.poll()); // first, second, third
}

// Peek without removing
queue.offer('peek-me');
print(queue.peek()); // 'peek-me'
print(queue.size()); // 1

Implementation

LinkedQueue([E? defaultValue]) : _defaultValue = defaultValue;