/*单链表的递归逆转, 笔试一般希望你递归法,简洁易懂*/
struct Note
{
int x = 0;
Note* next = nullptr;
};
Note* ReverseNote(Note* p)
{
if (p == nullptr || p->next == nullptr)
return p;
Note* t = ReverseNote(p->next);
p->next->next = p;
p->next = nullptr;
return t;
}
2024-01-04 15:46:34
/*单链表的递归逆转, 笔试一般希望你递归法,简洁易懂*/
struct Note
{
int x = 0;
Note* next = nullptr;
};
Note* ReverseNote(Note* p)
{
if (p == nullptr || p->next == nullptr)
return p;
Note* t = ReverseNote(p->next);
p->next->next = p;
p->next = nullptr;
return t;
}