# 原地逆置链表,不带返回的递归方法,能实现吗?

0

```#include <iostream>

using namespace std;

struct ListNode
{
int m_nValue;
ListNode* m_pNext;
};

int main(){

try
{

cout << "原始链表" << endl;

cout << endl << "有返回逆置,递归" << endl;

cout << endl << "原地逆置,递归" << endl;

}
catch(const std::exception &e)
{
std::cout << e.what() << std::endl;
}

system("pause");
return 0;
}

{ // 无返回,原地逆置,递归
return ;

// ?????????????????????????????????
// 此处怎样才能实现就地逆置    // 代码不能正确逆置
}

{ // 有返回,原地逆置,递归

}

{
{
}
else
{
while(p->m_pNext)
p = p->m_pNext;

ListNode* pEle = new ListNode();
pEle->m_nValue = e;
pEle->m_pNext = p->m_pNext;
p->m_pNext = pEle;
}
}

{
std::cout << "-------------------------------------------" << std::endl;

while(p != NULL) {
std::cout << p->m_nValue << ",";
p = p->m_pNext;
}
std::cout << std::endl;
}```

-------------------------------------------
1,2,3,

-------------------------------------------
3,2,1,
-------------------------------------------
1,2,3,

-------------------------------------------
1,
-------------------------------------------
1,

leungcnblogs | 初学一级 | 园豆：162

您需要登录以后才能回答，未注册用户请先注册