代码
#include <iostream>
using namespace std;
struct link {
int data;
link *next;
};
void reverse(link *head) {
if (head == NULL)
return;
link *cur, *pre = head, *next;
pre = head;
cur = head->next;
while (cur) {
next = cur->next;
cur->next = pre;
pre = cur;
cur = next;
}
head->next = NULL;
head = pre;
}