0% found this document useful (0 votes)
30 views9 pages

L10 - Circular LL

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views9 pages

L10 - Circular LL

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

CIRCULAR LINKED LIST

•Insert as a first node


•Insert as a last node

•Delete first node

•Delete last node

•Insert after a node

•Insert before a node

•Search

•Traverse
INSERT AS A FIRST NODE
void insertf()
{
struct studinfo *newnode,*ptr;
newnode=(struct studinfo *) malloc(sizeof(struct studinfo));
printf("Enter a new record : marks and name ");
scanf("%d%s",&newnode->marks,newnode->name);

if(start==NULL)
{
start = newnode;
newnode->next = newnode;
}
else
{
ptr = start;
while(ptr->next !=start)
ptr = ptr->next;
newnode->next = start;
start = newnode;
ptr->next =start;
}
}
INSERT AS A LAST NODE
void insertl()
{
struct studinfo *newnode, *ptr;
newnode=(struct studinfo *) malloc(sizeof(struct studinfo));
printf("Enter a new record : marks and name ");
scanf("%d%s",&newnode->marks,newnode->name);
if (start == NULL)
{
start =newnode;
newnode->next = newnode;
}
else
{
ptr =start;
while (ptr->next != start)
ptr= ptr->next;
ptr->next = newnode;
newnode->next = start;
}
}
INSERT AFTER A NODE

void inserta()
{
int cnt=1, no;
struct studinfo *ptr,*prevptr, *newnode;
printf("\n enter number ...");
scanf("%d",&no);
ptr=start;
while (cnt != no)
{
ptr = ptr->next;
cnt++;
}
newnode=(struct studinfo *) malloc(sizeof(struct studinfo));
printf("Enter a new record : marks and name");
scanf("%d%s",&newnode->marks,newnode->name);
newnode->next = ptr->next;
ptr->next = newnode;
}
INSERT BEFORE A NODE

void insertb()
{

int cnt=1, no;


struct studinfo *ptr,*prevptr, *newnode;
printf("\n enter number ...");
scanf("%d",&no);
ptr=start;
if(no==1)
{
insertf();
}
else
{
CONTINUE…
while(cnt !=no)
{
prevptr=ptr;
ptr = ptr->next;
cnt++;
}
newnode=(struct studinfo *) malloc(sizeof(struct
studinfo));
printf("Enter a new record : marks and name " );
scanf("%d%s",&newnode->marks,newnode-
>name);
newnode->next=ptr;
prevptr->next=newnode;
}
}
DELETE FIRST NODE
void deletef()
{
struct studinfo *ptrs,*ptr;
ptrs=start;
ptr = start;
if (start == NULL)
printf("\n List is empty, element can not be delete");
else
{
if (ptr->next == start)
start = NULL;
else
{
while(ptr->next !=start)
ptr = ptr->next;
start=start->next;
ptr->next = start;
}
free(ptrs);
}
}
DELETE LAST NODE

void deletel()
{
struct studinfo *ptr,*prevptr;
ptr=start;
if (start == NULL)
printf("\n List is empty, element can not be delete");
else
{
if (ptr->next == start)
start = NULL;
else
{
while(ptr->next!=start)
{
prevptr=ptr;
ptr=ptr->next;
}
prevptr->next =start;
}
free(ptr);
}
}
TRAVERSE
void traverse()
{
struct studinfo *ptr;
ptr= start;
if (ptr)
{
while (ptr->next !=start)
{
printf("\nRecord: marks and name %d %s\n",ptr->marks,
ptr->name);
ptr = ptr->next;
}
if (ptr)
printf("\nRecord: marks and name %d %s\n",ptr-
>marks, ptr->name);
}
else
printf("\nCircular list is empty ");
getch();
}

You might also like