Вы находитесь на странице: 1из 26

INSERTION AT END

& 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

//Since s is NULL, so it is first


insertion
Create node

Initially,

NULL
s

Insert 20 at
end:

NUL
L

//Since s is NULL, so it is first


insertion
20

Insert 20 in
data part

Initially,

NULL
s

Insert 20 at
end:

NUL
L
p

//Since s is NULL, so it is first


insertion
20

Store its
address in
pointer p

Initially,

NULL
s

Insert 20 at
end:

//Since s is NULL, so it is first


insertion
20

Make s point
to first node
// s=p;

Initially,

NULL
s

Insert 20 at
end:

//Since s is NULL, so it is first


insertion
20

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

Create node with data


50 and store its address
in pointer p

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

Вам также может понравиться