#include<stdio.h>
#include<conio.h>
typedef struct nodetype
{
int info;
struct nodetype *link;
}a;
a *head;
int main()
{
void addnode(int);
void display();
void del()
int value;
char choice;
head=(a*)malloc(sizeof(a));
head->link=head;
while(1)
{
printf("\nDo you wish to insert a node ( Y/N )?\n");
scanf("%c",&choice);
if(choice=='y'||choice=='Y')
{
printf("Enter the info of the new node: \n");
scanf("%d",&value);
addnode(value);
fflush(stdin);
}
else
{
break;
}
}
printf("\nThe circular linked list is ");
display();
del();
getch();
return 0;
}
void addnode(int data)
{
a *nptr=NULL;
nptr=(a*)malloc(sizeof(a));
nptr->info=data;
nptr->link=head->link;
head->link=nptr;
}
void display()
{
a *ptr=head->link;
if(ptr==head)
{
printf("Empty\n");
return;
}
printf("\n\n->");
while(ptr!=head)
{
printf("%d->",ptr->info);
ptr=ptr->link;
}
printf("\n");
}
void del()
{
a *ptr,*temp;
temp=head->link;
while(temp!=head)
{
ptr=temp;
temp=temp->link;
free(ptr);
}
free(head);
}
No comments:
Post a Comment