Often in a circular linked list you have a special link that does not contain meaningful data. Instead, it is a βsentinel,β letting you know where the list starts (and ends). This link will exist even if the list is empty, so your algorithms will work in all lists without special cases requiring special code.
class Link: def __init__(self, data, next): self.data = data self.next = next class CircularLinkedList: def __init__(self): self.head = Link(None, None)
source share