链表反转(迭代方法)
定义三个指针:
per:反转后的前一个节点
next:反转后的后一个节点
current:当前节点
struct ListNode* reverseList(struct ListNode* head){
struct ListNode* Per = NULL;
struct ListNode* current = head;
if(head != NULL)
{
struct ListNode* nxt = head->next;
while(current != NULL)
{
current->next = Per;
Per = current;
current = nxt;
if(nxt != NULL)nxt = nxt->next;
}
}
return Per;
}