# C Program for Deletion from beginning in Circular Linked List

## Deleting node from beginning in circular linked list

In this section we will learn C Program for Deletion from beginning in Circular Linked List, here removing first node from the linked list using the pointer to reach the last node of the list, then the last node of the list points to the head node of the list, then this will be changed the last node of the list will point to the second node of the linked list.

## Deletion From Beginning in Circular Linked List in C

### Algorithm

• Step 1:   IF HEAD = NULL ( GO TO STEP 8 )
• Step 2:   NOW SET POINTER = HEAD
• Step 3:   REPEAT STEP 4 UNTIL POINTER → NEXT != HEAD
• Step 4:   ASSIGN POINTER = POINTER → NEXT (END OF LOOP)
• Step 5:   ASSIGN POINTER → NEXT = HEAD → NEXT
• Step 6:   FREE HEAD NODE
• Step 7:   ASSIGN HEAD = POINTER → NEXT
• Step 8:   EXIT

### Construction of node in circular linked list :-

```struct node
{
int data;
struct node* next;
};```

### Implementation needed for deleting node at the beginning in the linked list

• CASE 1 :- If the linked list is empty then head == NULL and exit.
• CASE 2 :- If the linked  list have only single node then, head → next == head. In this scenario, we need to delete the list and make the head pointer free.
• CASE 3 :- If the linked list contains more than one node then,  we need to move whole linked list by using the pointer to reach the last node of the list.
• After that the pointer will point to the last node of the list. So, the last node of the list points to the head node of the list.
• Therefore we need to change it then, the last node of the list will point to the second node of the linked list.
• Now free the head node.
• At last make the node pointed by the next of the last node to the new head of the list.

### C Program For Deletion From Beginning in Circular Linked List

Run
```#include<stdio.h>
#include<stdlib.h>
// structure for Circular Linked List
struct Node
{
int data;
struct Node *next;
};

{

// if there are no nodes in Linked List can't delete
{
printf ("Linked List Empty, nothing to delete");
return;
}

// if only 1 node in CLL
{
return;
}

// traverse till last node in CLL
curr = curr->next;

// assign last node's next to 2nd node in CLL

// move head to next node
free (tempNode);
}

void insert (struct Node **head, int data)
{
struct Node *newNode = (struct Node *) malloc (sizeof (struct Node));
newNode->data = data;

{
return;
}

{
curr = curr->next;
}

curr->next = newNode;
}

{
// if there are no node in CLL
return;

//need to take care of circular structure of CLL
do
{
printf ("%d ", temp->data);
temp = temp->next;

}
printf ("\n");
}

int main ()
{

// first node will be null at creation

return 0;
}```
Output
```16 15 14 13 12 11 10
15 14 13 12 11 10
```

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

## Checkout list of all the video courses in PrepInsta Prime Subscription

• Introduction to Circular Linked List
• Circular Linked List in –
C | C++ | Java
• Insertion in Circular Linked List –
C | C++ | Java
• Insertion at the beginning–
C | C++ | Java
• Insertion at the end –
C | C++ | Java
• Insertion at nth position –
C | C++ | Java
• Deletion in Circular Linked List –
C | C++ | Java
• Deletion from beginning in Circular Linked List –
C | C++ | Java
• Deletion from nth position in Circular Linked List –
• Deletion from end in Circular Linked List –
C | C++ | Java
• Insertion and Deletion in Circular Linked List – C | C++ | Java
• Split a Circular Linked List in two halves –
C | C++ | Java
• Count nodes in Circular Linked List –
C | C++ | Java
• Sorted Insert In Circular Linked List –
C | C++ | Java
• Insertion in the middle in Circular Linked List –
C | C++ | Java