cdata-structureslinked-listcircular-list

Why exactly do we need a "Circular Linked List" (singly or doubly) data structure?


Why exactly do we need a "Circular Linked List" (singly or doubly) data structure?

What problem does it solve that is evident with simple Linked Lists (singly or doubly)?


Solution

  • Two reasons to use them:

    1) Some problem domains are inherently circular.

    For example, the squares on a Monopoly board can be represented in a circularly linked list, to map to their inherent structure.

    2) Some solutions can be mapped to a circularly linked list for efficiency.

    For example, a jitter buffer is a type of buffer that takes numbered packets from a network and places them in order, so that (for example) a video or audio player can play them in order. Packets that are too slow (laggy) are discarded.

    This can be represented in a circular buffer, without needing to constantly allocate and deallocate memory, as slots can be re-used once they have been played.

    It could be implemented with a linked-list, but there would be constant additions and deletions to the list, rather than replacement to the constants (which are cheaper).