All functions
#include <stdio.h>
typedef struct cll
{
int data;
struct cll*link;
}node;
node *newnode,*start=NULL,cur,prev,*temp,*last;
int main()
{
int ch;
char op;
void create();
void display();
void insatbegin();
void insatlast();
void insatrandom();
void delatbegin();
void delatlast();
void delatrandom();
printf(“enter your choice”);
printf(“1.create\n2. display\n3. insatbegin\n4. insatlast\n5. insatrandom\n6. delatbegin\n7. delatlast\n8. delatrandom\nexit”);
scanf(“%d”,&ch);
do
{
switch(ch)
{
case 1:create();
break;
case 2:display();
break;
case 3:insatbegin();
break;
case 4:insatlast();
break;
case 5:insatrandom();
break;
case 6:delatbegin();
break;
case 7:delatlast();
break;
case 8:delatrandom();
break;
case 9:exit(0);
break;
default:printf(“enter correct choice”);
}
}while(ch<9);
return 0;
}
void create()
{
int dp;
char op;
do
{
printf(“enter the datapart”);
scanf(“%d”,&dp);
newnode=(node*)malloc(sizeof(node));
newnode->data=dp;
newnode->link=NULL;
if(start==NULL)
{
start=newnode;
last=newnode;
last->link=start;
}
else
{
last->link=newnode;
last=newnode;
last->link=start;
}
printf(“do you want to continue”);
fflush(stdin);
scanf(“%c”,&op);
}while(op==’y’||op==’Y’);
}
void insatbegin()
{
int dp,pos=1;
printf(“enter the datapart”);
scanf(“%d”,&dp);
newnode->data=dp;
newnode->link=NULL;
if(pos=1)
{
start=newnode;
newnode->link=last;
}
else
{
temp=start;
while(temp->link!=NULL)
{
temp=temp->link;
}
last=temp;
newnode->link=start;
start=newnode;
last->link=start;
}
}
void insatlast()
{
int dp;
printf(“enter the datapart”);
scanf(“%d”,&dp);
newnode=(node*)malloc(sizeof(node));
newnode->data=dp;
newnode->link=NULL;
temp=start;
while(temp->link!=start)
{
temp=temp->link;
}
last=temp;
last->link=newnode;
last=newnode;
last->link=start;
}
void insatrandom()
{
int dp,pos,i=2;
printf(“enter the datapart”);
scanf(“%d”,&dp);
printf(“enter the position”);
scanf(“%d”,&pos);
newnode=(node*)malloc(sizeof(node));
newnode->data=dp;
newnode->link=NULL;
temp=start;
while((i<pos)&&(temp->link!=start))
{
temp=temp->link;
i++;
}
newnode->link=temp->link;
temp->link=newnode;
}
void delatbegin()
{
node *temp=start,*temp1;
if(start==NULL)
{
printf(“list is empty”);
}
else
{
while(temp->link!=start)
{
temp=temp->link;
}
temp1=start;
start=start->link;
temp->link=start;
temp1->link=NULL;
free(temp1);
}
}
void delatlast()
{
node *prev,*cur;
cur=start;
while(cur->link!=start)
{
prev=cur;
cur=cur->link;
}
prev->link=start;
free(cur);
}
void delatrandom()
{
node *prev,*cur;
int dp;
printf(“enter the datapart”);
scanf(“%d”,&dp);
cur=start;
while(cur->data!=dp&&cur->link!=start)
{
prev=cur;
cur=cur->link;
}
prev->link=cur->link;
free(cur);
}
void display()
{
node *temp=start;
printf(“start->”);
do
{
printf(“%d->”,temp->data);
temp=temp->link;
}while(temp!=start);
}