229 views

1 Answer

1 votes
1 votes

you are implementing circular queue, 

property of circular queue is last node should points to first node means, rear->link=front.

for better understanding, let new node = A

a new node is inserted at last, therefore

1) A = new node()  =====>  Rear -> link = new node()

 

update its value

2) A->data = x;  =====>  Rear -> link ->data = x; 

 

last element, next pointer should points to front

3) A->link = front  =====> rear->link->link = front

 

therefore your last element changed, therefore you have to change the pointer

4) rear=A =====> rear=rear->link


a new node is inserted at last, therefore

1) A = new node()  =====>  Rear -> link = new node()

 

update its value

2) A->data = x;  =====>  Rear -> link ->data = x; 

 

therefore your last element changed, therefore you have to change the pointer

3) rear=A =====> rear=rear->link

 

last element, next pointer should points to front

4) A->link = front  =====> rear->link = front

edited by

Related questions

0 votes
0 votes
0 answers
1
Sambhrant Maurya asked Jul 25, 2018
283 views
0 votes
0 votes
1 answer
2
Sambhrant Maurya asked Jul 25, 2018
371 views
a) Reverse the linked listb)Convert to circular linked listc)Converting a given singly linked list to have alternate nodes of singly linked listd)Converting a given singl...
0 votes
0 votes
1 answer
3
Sambhrant Maurya asked Jul 25, 2018
217 views
0 votes
0 votes
0 answers
4
Sambhrant Maurya asked Jul 25, 2018
236 views