ArrayList | List<T> |
Queue | Queue<T> |
SortedList | SortedDictionary<K,T> |
Stack | Stack<T> |
ICollection | ICollection<T> |
System.IComparable | IComparable<T> |
IDictionary | IDictionary<K,T> |
IEnumerable | IEnumerable<T> |
IEnumerator | IEnumerator<T> |
IList | IList<T> |
The Stack<T>
, Queue<T>
, and Dictionary<K,T>
generic classes are discussed in more detail in Chapter 13, 'Collections.'
Using the LinkedList<T> Generic Class
One of the new classes in the System.Collection.Generic
namespace is the LinkedList<T>
generic class. A
There are several types of linked lists:
□ Singly linked list
□ Doubly linked list
□ Circularly linked list
Figure 9-5 shows a singly linked list. Every node has a field that 'points' to the next node. To move from one node to another (known as

Figure 9-5
Figure 9-6 shows a doubly linked list. Doubly linked list nodes contains an additional field to point to the previous node. You can traverse a doubly linked list in either direction. The LinkedList<T>
class implements a doubly linked list.

Figure 9-6
Figure 9-7 shows a circularly linked list. A circularly linked list has its first and last node linked together. A circularly linked list can either be a singly linked list (as shown in Figure 9-5) or a doubly linked list.

Figure 9-7
The next example shows how to use the LinkedList<T>
class available in the .NET Framework to store a list of random numbers. As each random number is generated, it is inserted into the linked list in numeric sorted order (from small to big). The end result is a list of sorted random numbers. Specifically, the example uses the LinkedList<T>
class members shown in the following table.
Member | Description |
---|---|
AddAfter() | Adds a new node after an existing node |
AddBefore() | Adds a new node before an existing node |
First | Gets the first node |
Last | Gets the last node |
Each node in the LinkedList<T>
class is an object of type