C语言反转单向链表的代码

学习过程中中,把内容过程中常用的内容片段做个珍藏,下边内容段是关于C语言反转单向链表的内容,应该能对大伙有较大用处。

#include "stdafx.h"

enum{N = 3};
class Node
{
public:
int var;
Node(int i):pNext(NULL), var(i){}
};

{
if(pHead->pNext->pNext != NULL)
helper(pHead->pNext, reverseHead);
else
reverseHead = pHead->pNext;
pHead->pNext->pNext = pHead;
}

{
if(NULL == pHead || NULL == pHead->pNext)
return NULL;

helper(pHead, reverseHead);
pHead->pNext = NULL;
return reverseHead;

}

{
if(NULL == pHead || NULL == pHead->pNext)
{
return NULL;
}

if(NULL == N2)
{
    N1->pNext = pHead;
    pHead->pNext = NULL;
}
else
{
    while (NULL != N2)
    {
        N1->pNext = pHead;
        pHead = N1;
        N1 = N2;
        N2 = N2->pNext;
    }
    N1->pNext = pHead;
    t->pNext = NULL;
}

return N1;

}

{
while (pHead != NULL)
{
printf("%d ",pHead->var);
pHead = pHead->pNext;
}
printf("rn");
}

void Test()
{
for(int i = 1; i < N; i++)
{
pNode->pNext = pNext;
pNode = pNode->pNext;
}
PrintNode(pHead);
PrintNode(reversedHead);

}

{
Test();
return 0;
}

转载于:https://blog.51cto.com/14132786/2383993

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值