in DS retagged by
1,533 views
3 votes
3 votes

Consider the following function that takes reference to head of a Doubly Linked List as parameter. Assume that a node of doubly linked list has previous pointer as $\textit{prev}$ and next pointer as $\textit{next}$.

void fun(struct node **head_ref) 
{ 
struct node *temp=NULL; 
struct node *current=*head_ref; 
while(current!=NULL) 
{ 
 temp=current->prev; 
 current->prev=current->next; 
 current->next=temp; 
 current=current->prev; 
} 
if(temp!=NULL) 
*head_ref=temp->prev; 
} 

Assume that reference of head of following doubly linked list is passed to above function

$1 \leftrightarrow 2 \leftrightarrow 3 \leftrightarrow 4 \leftrightarrow 5 \leftrightarrow 6$. What should be the modified linked list after the function call? 

  1. $2 \leftrightarrow 1 \leftrightarrow 4 \leftrightarrow 3 \leftrightarrow 6 \leftrightarrow 5$
  2. $5 \leftrightarrow 4 \leftrightarrow 3 \leftrightarrow 2 \leftrightarrow 1 \leftrightarrow 6$
  3. $6  \leftrightarrow 5 \leftrightarrow 4 \leftrightarrow 3 \leftrightarrow 2 \leftrightarrow 1$
  4. $6 \leftrightarrow 5 \leftrightarrow 4 \leftrightarrow 3 \leftrightarrow 1 \leftrightarrow 2$
in DS retagged by
by
1.5k views

1 comment

C
0
0

Please log in or register to answer this question.

Answer:

Related questions