您好,登录后才能下订单哦!
学习过程中中,把内容过程中常用的内容片段做个珍藏,下边内容段是关于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;
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。