What would be the best way to create a circularly linked list in C#. Should I derive it from the LinkedList< T> collection? I\'m planning on creating a simple address boo
A modulus based solution.
If the circular buffer is implemented as a raw array (or any other kind of collection for what it matters)
T[] array;
and we store into int current_index
the index of the current item, we can cycle up and down the buffer as follows:
T NextOrFirst()
{
return array[(current_index + 1) % array.Length];
}
T PreviousOrLast()
{
return array[(current_index + array.Length - 1) % array.Length];
}
The same approach can be used with any XAML binding collection.