8,311 views
0 votes
0 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 prev and next pointer as 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 <--> 2 <--> 3 <--> 4 <--> 5 <-->6. What should be the modified linked list after the function call?

A)

2 <--> 1 <--> 4 <--> 3 <--> 6 <-->5

B)

5 <--> 4 <--> 3 <--> 2 <--> 1 <-->6.

C)

6 <--> 5 <--> 4 <--> 3 <--> 2 <--> 1.

D)

6 <--> 5 <--> 4 <--> 3 <--> 1 <--> 2

1 Answer

1 votes
1 votes

I have explained this question using some addresses .....hope so my explanation make some sense...:)

Related questions

0 votes
0 votes
1 answer
2
Arnab Bhadra asked Jun 28, 2017
3,311 views
Insertion of a node into a doubly linked list requires how many changes to various Next and Previous Pointer?A. No ChangeB. 1 Next , 1 PreviousC. 2 Next , 2 PreviousD. 3 ...
0 votes
0 votes
2 answers
4