Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include<stdio.

h>
#include<conio.h>
#include<stdlib.h>
void insertcll(struct node**);
void trvs(struct node *);
void del(struct node**);
struct node
{
int info;
struct node *next;
};
void main()
{
int i,n;
struct node *head=NULL;
printf("No. of Nodes you want to insert:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
insertcll(&head);
}
printf("\n\nThe CLL after the Insertion:\n\n");
trvs(head);
del(&head);
printf("\n\nThe CLL after the Deletion:\n\n");
trvs(head);
}
void insertcll(struct node **head)
{
int item;
struct node *p=*head,*newnode;
newnode=(struct node*)malloc(sizeof(struct node*));
if(newnode= =NULL)
{
printf("Overflow condition , Failed to create new node");
exit(0);
}
printf("Plzz Enter the Data Item:");
scanf("%d",&item);

newnode->info=item;
newnode->next=newnode;
if(*head= =NULL)
{
*head=newnode;
}
else
{
while(p->next!=*head)
p=p->next;
newnode->next=*head;
p->next=newnode;
*head=newnode;
}
}

void trvs(struct node *head)


{
struct node *p=head;
do
{
printf("%d -> ",p->info);
p=p->next;
}
while(p!=head);
printf("NULL");
}
void del(struct node **head)
{
struct node *p=*head,*q;
if(*head= =NULL)
{
printf("Underflow Condition Occurred, Deletion Cannot be
performed");
exit(0);
}
while(p->next!=*head)
{
q=p;

p=p->next;
}
q->next=p->next;
free(p);
p=NULL;
}

You might also like