Yelp interview question

Write a function which reverses a linked list.

Interview Answer

Anonymous

May 5, 2016

Node * reverse(Node *head){ Node * prev=head; Node *curr=head->next; Node * next=head->next->next; while(next!=NULL){ curr->next=prev; prev=curr; curr=next; next=next->next; } return curr; }

1