O'Reilly logo

C# Data Structures and Algorithms by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required