975 views
1 votes
1 votes

Consider the following Linked list Node structure

struct Node
{
    int data;
    struct Node * next;
}
typedef struct Node Node;

Consider the following function to reverse the singly linked list

Node* reverse_list(Node *head)
{
    Node *temp = NULL;
    Node *next ;
    while(head)
    {
        next = 1)------;
        head->next = temp;
        temp = head;
        head = 2)-------;
    }
    return temp;
}

What are the missing expressions at 1 and 2 respectively

(A) head, head->next
(B) head->next,head
(C) NULL, head->next
(D) head->next, next

1 Answer

0 votes
0 votes
Answer is option D as we store head->next in temp and make it null and reverse it by making head point to last node and initial first node becomes last node

Related questions

2 votes
2 votes
0 answers
2