recategorized by
14,125 views
23 votes
23 votes

In a circular linked list organization, insertion of a record involves modification of

  1. One pointer.
  2. Two pointers.
  3. Multiple pointers.
  4. No pointer.
recategorized by

3 Answers

Best answer
29 votes
29 votes

Suppose we have to insert node $p$ after node $q$ then

  • $p \rightarrow \text{next} =q \rightarrow \text{next}$
  • $q \rightarrow \text{next}=p$

So, two pointers,

Answer is (B).

edited by
10 votes
10 votes

Image result for insertion in circular linked list

So Option B is correct

6 votes
6 votes

Note that in a circular linked list, the next of the last node points to the head of the list.

 

Let $\mathrm{p}$ be a variable pointer and $\mathrm{head}$ is the pointer of the circular linked list.

Now to insert a new record (node) $\mathrm{q}$, we have to loop through the linked list from the head to the last node like this pseudocode below.

p=head
while(p->next!=head)
{
    p=p->next;
}

After finishing the loop, we will reach the last node meaning that $\mathrm{p}$ is now the last node. So we need to append the new node $\mathrm{q}$ to the next of $\mathrm{p}$. Then finally the next of $\mathrm{q}$ will have to point to the head since the linked list is circular. The pseudocode for this task is below.

p->next=q;
q->next=head;

 

$\therefore$ There needs modification of two pointers.

 

So the correct answer is B.

edited by
Answer:

Related questions

18 votes
18 votes
3 answers
2
makhdoom ghaya asked Nov 14, 2016
5,090 views
Construct a binary tree whose preorder traversal is$K\;L\;N\;M\;P\;R\;Q\;S\;T$and inorder traversal is$N\;L\;K\;P\;R\;M\;S\;Q\;T$
19 votes
19 votes
3 answers
3
makhdoom ghaya asked Nov 9, 2016
4,837 views
State whether the following statements are TRUE or FALSE:If the number of leaves in a tree is not a power of $2,$ then the tree is not a binary tree.
31 votes
31 votes
5 answers
4
makhdoom ghaya asked Nov 9, 2016
6,445 views
State whether the following statements are TRUE or FALSE:It is possible to construct a binary tree uniquely whose pre-order and post-order traversals are given?