溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

C語言反轉(zhuǎn)單向鏈表的代碼

發(fā)布時(shí)間:2020-07-08 17:48:24 來源:網(wǎng)絡(luò) 閱讀:341 作者:塵埃落定啊 欄目:編程語言

學(xué)習(xí)過程中中,把內(nèi)容過程中常用的內(nèi)容片段做個(gè)珍藏,下邊內(nèi)容段是關(guān)于C語言反轉(zhuǎn)單向鏈表的內(nèi)容,應(yī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;
}

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI