Class LinkedListQueue<T>
A IQueue<T> implementation based on a singly-linked linked list of items.
Inheritance
Implements
Inherited Members
Namespace: MoreStructures.Queues
Assembly: MoreStructures.dll
Syntax
public class LinkedListQueue<T> : IQueue<T>
Type Parameters
Name | Description |
---|---|
T |
Remarks
ADVANTAGES AND DISADVANTAGES
- The advantages and disadvantages of using a linked list over an array-based implementation are the same
as the ones described in LinkedListStack<T>.
Properties
| Improve this Doc View SourceCount
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
Stored and updated in constant time at each Enqueue(T) and Dequeue().
Time and Space Complexity are O(1).
Methods
| Improve this Doc View SourceDequeue()
Declaration
public T Dequeue()
Returns
Type | Description |
---|---|
T |
Remarks
First, it retrieves the item referenced by the front of the underlying linked list.
Then it updates the reference to the head of the linked list, to point to its "next".
The reference to the last item is also updated, if the head is set to point to null.
Time and Space Complexity are O(1).
Enqueue(T)
Declaration
public void Enqueue(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
Remarks
Creates a new node wrapping the provided item
.
Then, it appends it to the back of the linked list of items, updating the reference to the last item of the
list.
It also updates the head, if the list was previously empty, to point to the newly created item.
Time and Space Complexity are O(1).
Peek()
Declaration
public T Peek()
Returns
Type | Description |
---|---|
T |
Remarks
Checks the front of the underlying linked list.
Time and Space Complexity are O(1).