1. Insert a node at beginning
2. Insert a node at end
3. Delete a node from beginning
4. Delete a node from end
5. Count number of nodes in Circular linked
list
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *rnext;
struct node*lnext;
}*first=NULL,*last=NULL;
void display()
{
struct node*temp;
if(first==NULL)
{
printf("list is empty\n");
return;
}
temp=first;
while(temp!=NULL)
{
printf("%d \n",temp->data);
temp=temp->rnext;
}
}
void insertion()
{
struct node *temp;
struct node *nn= (struct node*) malloc(sizeof(struct node));
printf("enter data to be inserted\n");
nn->rnext=NULL;
last->rnext=nn;
nn->lnext=last;
last=nn;
}
void deletion()
{
struct node *temp;
if(first==NULL||last==NULL)
{
printf("list is empty\n");
return;
}
temp=first;
first=first->rnext;
first->lnext=NULL;
free(temp);
}
/* main loop */
int main()
{
int option;
do
{
printf("enter option 1.insertion\n2.display\n3.deletion\n4.exit\n");
scanf("%d",&option);
switch(option)
{
case 1:
insertion();
break;
case 2:
display();
break;
case 3:
deletion();
break;
}
} while(option!=4);
}
Comments
Leave a comment