Implementation

After the short introduction to the topic of circular-linked lists, it is time to take a look at the implementation code. Let's start with the following code snippet:

public class CircularLinkedList<T> : LinkedList<T> 
{ 
    public new IEnumerator GetEnumerator() 
    { 
        return new CircularLinkedListEnumerator<T>(this); 
    } 
} 

The implementation of the circular-linked list can be created as a generic class that extends LinkedList, as shown in the preceding code. It is worth mentioning the implementation of the GetEnumerator method, which uses the CircularLinkedListEnumerator class. By creating it, you will be able to indefinitely iterate through all the elements of the circular-linked list, using the foreach loop.

The code of the CircularLinkedListEnumerator ...

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.