Data Structure

## Insertion At Last in Circular linked list

### Procedure for insertion a node at the Last 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 last of Circular linked list

```node* AddEnd(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 temp;
}
```

### C function for insertion at Last

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

### C programe for insertion at last 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++;
}
}
{
int count;
node=start->next;
ptr=start;
count=i;
while(count)
{
ptr=ptr->next;
node=node->next;
count--;
}
printf("\n Insert data for last 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();