Queue<E>.withCapacity constructor
Queue<E>.withCapacity (
- int capacity
Creates a Queue with the specified initial capacity.
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.withCapacity(int capacity) : _elements = <E>[];