Consider the following incomplete C function for reversing a singly linked list.
node* reverse(node* trav){ if(trav->next) __________________ else { head -> next = null; head = trav; } return trav; }
Here, head is a global pointer pointing to the head of the list and where the head of the reversed list is supposed to be returned. The missing line can be correctly filled by:
Recursive Function to reverse linked list : node* reverse(node* trav){ if(trav->next) reverse(trav->next) = trav; else head = trav; return trav; }
@arjun SIr please confirm ??
After reverse : Last node next ptr should be set to null, somehow right ?
Either it has be managed inside this code or some other way. correct ?
64.3k questions
77.9k answers
244k comments
80.0k users