Data Structure

## Insertion At Beginning in Circular linked list

### Procedure for insertion a node at the beginning of list

Step1. Create the new node
Step2. Set the new node’s next to itself (circular!)
Step3. If the list is empty,return new node.
Step4. Set our new node’s next to the front.
Step5. Set tail’s next to our new node.
Step6. Return the end of the list.

### Algorithm for Insertion at the front of Circular linked list

```node* AddFront(node* tail, int num)
{
node *temp = (node*)malloc(sizeof(node));
temp->data = num;
temp->next = temp;
if (tail == NULL)
return temp;
temp->next = tail->next;
tail->next = temp;
return tail;
}
```

### C function for insertion at begining

```void insert_first(struct link *node)
{
node=start->next;
ptr=start;
printf("\n Insert data for first node:");
scanf("%d",&new1->data);
ptr->next=new1;
new1->next=node;
i++;
}
```

### C programe for insertion at begining in Circular linked list

```#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
{
int data;
};
int i=0;

{
char ch;
start->next=NULL;
node=start;
fflush(stdin);
printf("\n Enter 'n' for break:");
ch=getchar();
while(ch!='n')
{
node=node->next;

printf("\n Enter data for node:");
scanf("%d",&node->data);
node->next=start;
fflush(stdin);
printf("\n Enter 'n' for break:");
ch=getchar();
i++;
}
}
{
node=start->next;
ptr=start;
printf("\n Insert data for first node:");
scanf("%d",&new1->data);
ptr->next=new1;
new1->next=node;
i++;
}

{
int count;
node=start->next;
count=i;

while(count)
{
printf("\t%d",node->data);
node=node->next;
count--;
}
}

void main()
{
char ch;
clrscr();
insert_first(node);
printf("List Item Are:\n");
display(node);
getch();
}
```

### Output

`About Me`