學(xué)習(xí)過程中中,把內(nèi)容過程中常用的內(nèi)容片段做個(gè)珍藏,下邊內(nèi)容段是關(guān)于C語言反轉(zhuǎn)單向鏈表的內(nèi)容,應(yīng)該能對(duì)大伙有較大用處。
我們提供的服務(wù)有:成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè)、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、忻城ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的忻城網(wǎng)站制作公司
#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;
}