A circular linked list is a linked list designed to keep going. Instead of ending with a null reference, the tail node points back to the head, forming a cycle. This makes it useful when items, resources, or tasks must repeat rather than stop. section 6.21 section 6.24
Use the linked-node diagram to trace how the tail returns to the head instead of reaching an endpoint. section 6.22
Choose the link direction according to how the cycle must be traversed:
- Use a circular singly linked list when traversal only moves forward, such as through a slideshow, agricultural cycle, or server list. section 6.22
- Use a circular doubly linked list when traversal must move forward and backward, such as through a carousel or revisable process. section 6.22
- Stop traversal deliberately: because every node has a successor, an ordinary loop can continue forever. section 6.23
- For a circular doubly linked list, the tail can be reached as head.prev; step-by-step traversal can track a current node. section 6.23
A repeating slideshow
A slideshow that displays images in order and starts again after the final image needs only forward movement, so a circular singly linked list fits. A carousel that lets users move backward as well as forward needs the doubly linked version. section 6.22
Implementation requires only small changes to a regular linked-list design, but insertion and deletion must preserve the cycle. If step-by-step traversal is supported, updates must also keep the current-traversal pointer correct. Earlier linked-list classes may be reusable through composition or inheritance. section 6.23
