Click or drag to resize
LinkedQueueItem Class

The LinkedQueue class represents a first-in-first-out (FIFO) queue of generic items. So named to avoid conflict with the .NET framwork QueueT class. Since C# does not allow an inner static class with instances, the implementation is effectively the same as the Queue class implementation.

It supports the usual Enqueue and Dequeue operations, along with methods for peeking at the first item, testing if the queue is empty, and iterating through the items in FIFO order.

This implementation uses a singly-linked list with a nested, non-static class Node and hence is the same as the Queue class in algs4.jar. The Enqueue, Dequeue, Peek, Count, and IsEmpty operations all take constant time in the worst case.

Inheritance Hierarchy
SystemObject
  Algs4NetLinkedQueueItem

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class LinkedQueue<Item> : IEnumerable<Item>, 
	IEnumerable

Type Parameters

Item

The LinkedQueueItem type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCount
Returns the number of items in this queue.
Public propertyIsEmpty
Is this queue empty?
Top
Methods
  NameDescription
Public methodDequeue
Removes and returns the item on this queue that was least recently added.
Public methodEnqueue
Adds the item to this queue.
Public methodGetEnumerator
Returns an iterator that iterates over the items in this queue in FIFO order.
Public methodStatic memberMainTest
Demo test the LinkedQueue data type.
Public methodPeek
Returns the item least recently added to this queue.
Public methodToString
Returns a string representation of this queue.
(Overrides ObjectToString.)
Top
Remarks
For additional documentation, see Section 1.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class LinkedQueue implementation by Robert Sedgewick and Kevin Wayne.

See Also