A circular linked list can have only one reference direction (as with a linked list) or a double reference (as with a doubly linked list). The only difference between a circular linked list and a linked list is that the last element's next (tail.next) pointer does not make a reference to undefined, but to the first element (head), as we can see in the following diagram:
![](https://static.packt-cdn.com/products/9781788623872/graphics/assets/0a1e380a-8cb0-4f47-9b45-820a75978b04.png)
A doubly circular linked list has tail.next pointing to the head element, and head.prev pointing to the tail element:
![](https://static.packt-cdn.com/products/9781788623872/graphics/assets/d9e4486a-e321-463c-896e-4ad3869477da.png)
Let's check the code to create the CircularLinkedList class:
CircularLinkedList extends LinkedList {
constructor(equalsFn = defaultEquals) {
super(equalsFn);
}
}
The CircularLinkedList class does not need any additional properties, so we can simply extend the LinkedList class and overwrite the required methods to apply the special behavior.
We will overwrite...