A linked list in which all the elements are connected to form a circle chain is circular linked list.there is no null at the end.it can be singly or doubly circular linked list

Implementation:

To implement a circular singly linked list, we take an external pointer that points to the last node of the list. If we have a pointer last pointing to the last node, then last -> next will point to the first node.

The pointer last points to node Z and last -> next points to the node P.

For insertion of node in the beginning we need traverse the whole list. Also, for insertion and the end, the whole list has to be traversed. If instead of start pointer we take a pointer to the last node then in both the cases there won’t be any need to traverse the whole list. So insertion in the begging or at the end takes constant time irrespective of the length of the list, so we have taken last pointer.

Below is a sample program to create and traverse in a Circular Linked List:

c++:

```// A complete C++ program to demonstrate the
// working of Circular Linked Lists

#include<bits/stdc++.h>
using namespace std;

struct Node
{
int data;
struct Node *next;
};

// Function to add a node at the end of a
struct Node *addEnd(struct Node *last, int data)
{
if (last == NULL)
{
// Creating a node dynamically.
struct Node *temp = new Node;

// Assigning the data.
temp -> data = data;
last = temp;

last -> next = last;

return last;
}

struct Node *temp = new Node;

temp -> data = data;
temp -> next = last -> next;
last -> next = temp;
last = temp;

return last;
}

// Function to traverse a Circular Linked list
// Using a pointer to the Last Node
void traverse(struct Node *last)
{
struct Node *p;

// If list is empty, return.
if (last == NULL)
{
cout << "List is empty." << endl;
return;
}

// Pointing to first Node of the list.
p = last -> next;

// Traversing the list.
do
{
cout << p -> data << " ";
p = p -> next;

}
while(p != last->next);

}

// Driver Program
int main()
{
struct Node *last = NULL;

traverse(last);

return 0;
} ```

Java:

```  // A complete Java program to demonstrate the
// working of Circular Linked Lists

class CLL
{
// A circular linked list node
static class Node
{
int data;
Node next;
};

// Function to insert a node in a Circular
// linked list at the end
static Node addEnd(Node last, int data)
{
if (last == null)
{
// Creating a node dynamically.
Node temp = new Node();

// Assigning the data.
temp.data = data;
last = temp;

last.next = last;

return last;
}

Node temp = new Node();

temp.data = data;
temp.next = last.next;
last.next = temp;
last = temp;

return last;
}

// Function to traverse a given Circular Linked
// List using the Last pointer
static void traverse(Node last)
{
Node p;

// If list is empty, return.
if (last == null)
{
System.out.println("List is empty.");
return;
}

// Pointing to first Node of the list.
p = last.next;

// Traversing the list.
do
{
System.out.print(p.data + " ");
p = p.next;

}
while(p != last.next);

}

// Driver code
public static void main(String[] args)
{
Node last = null;

traverse(last);
}
} ```

output:

`45 6 93 5 12 10`