Circular Linked List
Circular Linked List
& BEGINING
IN
CIRCULAR LINKED
BY
Mr.
LIST
Shubham Sidana
Assistant Professor
ABES Engineering College
Dr. A.P.J. Abdul Kalam Technical
University
Initially,
NULL
s
Initially,
NULL
s
Insert 20 at
end:
NULL
s
Initially,
NULL
s
Insert 20 at
end:
NUL
L
Insert 20 in
data part
Initially,
NULL
s
Insert 20 at
end:
NUL
L
p
Store its
address in
pointer p
Initially,
NULL
s
Insert 20 at
end:
Make s point
to first node
// s=p;
Initially,
NULL
s
Insert 20 at
end:
Make circular
link
// s->next=s;
20
Insert 30 at
end:
20
30
Create node
with data 30
& Store its
address in
pointer p
20
Insert 30 at
end:
temp
20
30
while(temp->next!
= s)
{
temp=temp>next;
}
20
Insert 30 at
end:
temp
20
30
temp->next = p;
20
Insert 30 at
end:
temp
20
30
p ->next = s;
20
30
Insert 40 at
end:
20
40
30
Create node
with data 40
& Store its
address in
pointer p
20
30
Insert 40 at
end:
20
40
30
p
temp
while(temp>next! = s)
{
temp=temp>next;
}
20
30
Insert 40 at
end:
20
40
30
p
temp
while(temp>next! = s)
{
temp=temp>next;
}
20
30
Insert 40 at
end:
20
40
30
p
temp
temp->next = p;
20
30
Insert 40 at
end:
20
40
30
p
temp
p ->next = s;
20
40
30
Insert 50 at
Beginning:
50
20
30
40
20
40
30
Insert 50 at
Beginning:
50
20
30
temp
while(temp->next! =
s)
{
temp=temp->next;
}
40
20
40
30
Insert 50 at
Beginning:
50
20
30
temp
while(temp->next! =
s)
{
temp=temp->next;
}
40
20
40
30
Insert 50 at
Beginning:
50
20
40
30
temp
while(temp->next! =
s)
{
temp=temp->next;
}
20
40
30
Insert 50 at
Beginning:
50
20
30
40
temp
temp->next = p;
20
40
30
Insert 50 at
Beginning:
50
20
30
40
temp
p->next = s;
20
40
30
Insert 50 at
Beginning:
s
p
50
20
30
40
temp
s = p;
20
40
30
Insert 50 at
Beginning:
s
p
50
20
30
40
temp
s = p;
Note: This last step differentiates
INSERT AT END & INSERT AT
BEGINNING
Which is extra in Insert at Beginning
void ins_at_end()
{
struct node *p, *temp;
temp = s;
p = (struct node*)malloc(sizeof(struct node));
printf("\n Enter the data:");
scanf("%d", &pdata);
if ( s = = NULL )
{
s = p;
s next = s;
return;
}
while (tempnext != s)
{
temp = temp next;
}
tempnext = p;
pnext = s;
}
Insert at END
void ins_at_beg()
{
struct node *p, *temp;
temp = s;
p = (struct node*)malloc(sizeof(struct node));
printf("\n Enter the data:");
scanf("%d", &pdata);
if ( s = = NULL )
{
s = p;
s next = s;
return;
}
while (tempnext != s)
{
temp = temp next;
}
tempnext = p;
pnext = s;
s = p; }
Insert at
beginning