在微软某年的笔试题中看到了一段比较完美的链表转置代码,特在此与大家分享:
struct node{
void* data;
struct node* next;
};
struct node* reverse(struct node*head)
{
struct node* prev, *curr, *next;
prev = NULL;
curr = head;
while(curr != NULL)
{
next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}