#include <iostream>
#include<vector>
#include<string>
using namespace std;
struct ListNode{
ListNode* next;
int value;
ListNode(int val)
{
value=val;
next=nullptr;
}
};
ListNode* FZ(ListNode* head)
{
ListNode* pre=head;
ListNode* cur=nullptr;
ListNode* tmp;
while(pre!=nullptr)
{
tmp=pre->next;
pre->next=cur;
cur=pre;
pre=tmp;
}
ListNode* LN=cur;
while(cur!=nullptr)
{
cout<<cur->value;
cur=cur->next;
}
return LN;
}
int main()
{
ListNode* node1=new ListNode(1);
ListNode* node2=new ListNode(2);
ListNode* node3=new ListNode(3);
ListNode* node4=new ListNode(4);
node4->next=nullptr;
node3->next=node4;
node2->next=node3;
node1->next=node2;
FZ(node1);
return 0;
}
反转链表实例
最新推荐文章于 2021-11-13 19:12:42 发布