码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-04-24 17:30:38      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:class   nod   ret   int   反转   i++   应该   seh   ever   

学习过程中中,把内容过程中常用的内容片段做个珍藏,下边内容段是关于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;
}

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

标签:class   nod   ret   int   反转   i++   应该   seh   ever   

原文地址:https://blog.51cto.com/14132786/2383993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!