标签: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;
}
标签:class nod ret int 反转 i++ 应该 seh ever
原文地址:https://blog.51cto.com/14132786/2383993