The Gateway to Computer Science Excellence
+1 vote
In a circular single linked list how many external pointers are there because in some books there are two external pointers start pointing at first node and last pointing at last node while some given only last pointer and some have only first pointer
in DS by | 292 views
Two external pointers are required.

One should point to the node we are traversing and another one should point to the first node. Pointer to the first node is required to avoid infinite loop while traversing the circular linked list.

P.S. In GATE questions they will mention what pointers we have.

1 Answer

0 votes

if we take *last as a pointer pointing to the last node of the list then  we can point to the start node in o(1) by 

Node *start=last->next;

and can do any thing that we can doing using the start as a pointer  ,that's simple

so its your choice but we can achieve it using one pointer only

but i will suggest u to use last, because insertion at beginning and deletion at the beginning will cost u o(n) if u use start 

because u will have to traverse all the list to find the last node so that after the insertion or the deletion option u can update the links.


Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,489 answers
95,297 users