C语言反转单向链表的代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}
以上是关于C语言反转单向链表的代码的主要内容,如果未能解决你的问题,请参考以下文章