#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node* next;
}node;
struct node* head;
void insertCircularAtEnd(int x)
{
struct node* temp=NULL;
temp=(node*)malloc(sizeof(struct node));
temp->data=x;
if(head==NULL)
{
head=temp;
temp->next=head;
}
else
{
struct node* last=head;
while(last->next!=head)
{
last=last->next;
}
struct node* temp2=NULL;
temp2=(node*)malloc(sizeof(struct node));
temp2->data=x;
last->next=temp2;
temp2->next=head;
}
}
void print()
{
struct node* temp=head;
while(temp->next !=head)
{
printf("%d",temp->data);
temp=temp->next;
}
while(temp->next ==head)
{
printf("%d",temp->data);
temp=temp->next;
}
}
void main()
{
insertCircularAtEnd(2);
insertCircularAtEnd(3);
insertCircularAtEnd(4);
insertCircularAtEnd(5);
print();
getch();
}This code snippet is for Circular linked list Insert at End.
