//Create a circular linked list.
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct node
{
int data;
struct node *next;
};
main()
{
struct node *start=NULL;
int n;
void create(struct node **, int);
void show(struct node *);
printf("Enter the number of elements you want in your linked list :");
scanf("%d",&n);
create(&start,n);
show(start);
getch();
}
void create(struct node **start,int n)
{
int i;
struct node *lst;
struct node *p,*head;
head=(struct node *)malloc(sizeof(struct node));
*start=head;
head->next=head;
lst=NULL;
for(i=1;i<=n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
printf("Enter the %d element :",i);
scanf("%d",&(p->data));
p->next=*start;
if((*start)->next==*start)
(*start)->next=p;
else
lst->next=p;
lst=p;
}
}
void show(struct node *start)
{
struct node *temp;
printf("Entered linked list is :\n");
temp=start->next;
while(temp!=start)
{
printf(" %d\n",temp->data);
temp=temp->next;
}
}
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct node
{
int data;
struct node *next;
};
main()
{
struct node *start=NULL;
int n;
void create(struct node **, int);
void show(struct node *);
printf("Enter the number of elements you want in your linked list :");
scanf("%d",&n);
create(&start,n);
show(start);
getch();
}
void create(struct node **start,int n)
{
int i;
struct node *lst;
struct node *p,*head;
head=(struct node *)malloc(sizeof(struct node));
*start=head;
head->next=head;
lst=NULL;
for(i=1;i<=n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
printf("Enter the %d element :",i);
scanf("%d",&(p->data));
p->next=*start;
if((*start)->next==*start)
(*start)->next=p;
else
lst->next=p;
lst=p;
}
}
void show(struct node *start)
{
struct node *temp;
printf("Entered linked list is :\n");
temp=start->next;
while(temp!=start)
{
printf(" %d\n",temp->data);
temp=temp->next;
}
}