#include<iostream>
using namespace std;
struct ListNode {
int value;
ListNode* next;
};
ListNode* ReverseList(ListNode* head){
if (!head) return NULL;
ListNode*p=head, *q=NULL,*h=head->next;
while (h){
q = h;
h = q->next;
q->next = p;
p = q;
}
return p;
}
int main(){
ListNode *l = new ListNode();
l->value = 1;
cout << ReverseList(l)->value << endl;
l->next = new ListNode();
l->next->value = 2;
l->next->next = new ListNode();
l->next->next->value = 3;
l->next->next->next = new ListNode();
l->next->next->next->value = 4;
ListNode * k = ReverseList(l);
cout <<k->value<<" "<< k->next->value << " " << k->next->next->value << " " << k->next->next->next->value <<endl;
return 0;
}
剑指offer24
最新推荐文章于 2023-03-20 16:22:52 发布