• Write a C program to convert a singly linked list to a circular linked list.
• How to make a circular linked list from singly linked list.

Given a singly linked list, we have to convert it to a circular linked list. We have to set the next pointer of tail node to point back to head node to complete a cycle.

Let "head" be the head pointer of given linked list. Singly linked list is a linear data structure, which can be traversed from first node(head node) till last node(tail node) in one direction. Tail node of linked list points to NULL, Hence it is a dead end. We cannot traverse beyond tail node. To convert a singly linked list to circular linked list, we will set next pointer of tail node to head pointer.
• Create a copy of head pointer, let's say "temp".
• Using a loop, traverse linked list till tail node(last node) using temp pointer.
• Now set the next pointer of tail node to head node. (temp->next = head;)

In this program, we will use a user defined function "convertToCircularLL" which takes head node of singly linked list as input and converts it to a Circular linked list by implementing above algorithm.

```void convertToCircularLL(struct node *head){
/* Input Validation */
printf("Error : Invalid Input !!!!\n");
return INT_MIN;
}
while(temp->next != NULL){
temp = temp->next;
}

}
```

## C program to convert a singly linked list to circular linked list

```#include <stdio.h>
#include <stdlib.h>

/* A structure of linked list node */
struct node {
int data;
struct node *next;

void initialize(){
}

/*
Given a Inserts a node in front of a singly linked list.
*/
void insert(int num) {
/* Create a new Linked List node */
struct node* newNode = (struct node*) malloc(sizeof(struct node));
newNode->data  = num;
/* Next pointer of new node will point to head node of linked list  */
printf("Inserted Element : %d\n", num);
}

/* Input Validation */
printf("Error : Invalid Input !!!!\n");
return INT_MIN;
}
while(temp->next != NULL){
temp = temp->next;
}

}

/*
*/
do {
printf("%d ", temp->data);
temp = temp->next;
}

int main() {
initialize();
insert(1);
insert(2);
insert(3);
insert(4);
insert(5);

/* Printing Circular Linked List */
return 0;
}
```
Output
```Inserted Element : 1
Inserted Element : 2
Inserted Element : 3
Inserted Element : 4
Inserted Element : 5
5 4 3 2 1
```