赞
踩
LinkList Reverse_List(LinkList L) {
LNode *p, *r;
p = L->next;
L->next = null;//断链,头节点和真正存储数据的结点断开
while(p != null) {
r = p->next;
p->next = L->next;
L->next = p;
p = r;
}
return L;
}
ListNode* reverseList(ListNode* head) {
ListNode *prev = nullptr;
ListNode *curr = head;
ListNode *next;
while(curr != nullptr) {
next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。