反转单向链表
代码语言:javascript复制void ReverseList(Node* head) {
//反转带头节点指针的单向链表
Node* pre = NULL;
Node* cur = head->next;
Node* nex = cur->next;
while (cur != NULL) {
cur->next = pre;
pre = cur;
cur = nex;
nex = (nex == NULL) ? NULL : nex->next;
}
head->next = pre;
}