Implementation of Circular Linked List

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

WAP TO SHOW THE IMPLEMENTATION OF CIRCULAR LINKED

LIST

#include<conio.h>
#include<stdio.h>
struct node
{
struct node *next;
int info;
};
struct node *head;
void insert_end(int i) //FUNCTION TO INSERT IN A CIRCULAR LINKED LIST
{
struct node *temp,*trav;
if(head==NULL)
{
temp=malloc(sizeof(struct dnode));
temp->info=i;
head=temp;
temp->next=head;
}
else
{
trav=head;
while(trav->next!=head)

trav=trav->next;
temp=malloc(sizeof(struct dnode));
temp->info=i;
temp->next=head;
head=temp;
trav->next=head;

}
}

void display() //FUNCTION TO DISPLAY THE CIRCULAR LINKED LIST


{
struct node *trav;
trav=head;
if(trav= =NULL)
printf(“\n LIST IS EMPTY.”);
while(trav->next!=head)
{
printf(“\n%t”,trav->info);
trav=trav->next;
}
}
void delete_end() //FUNCTION TO DELETE IN A CIRCULAR LINKED LIST

{
struct node *trav,ptr;
trav=head;
if(trav= =NULL)
printf(“\n LIST IS EMPTY.”);
else
{
while(trav->next!=head)
{
trav=trav->next;
}
ptr=head;
head =head->next;
trav->next=head;
printf(“\n ELEMENT DELETED IS-:”,ptr->info);
free(ptr);
}
}

void main()
{
clrscr();
insert_beg(20);
insert_beg(30);
delete_end();
insert_beg(40);
insert_beg(50);
delete_end();
insert_beg(60);
insert_beg(70);
display();
getch();
}

OUTPUT

20 40 60 70

You might also like