十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
頭文件如下:
#ifndef _SLIST_H_
#define _SLIST_H_
typedef int SLTDataType;
typedef struct SListNode
{
SLTDataType data;
struct SListNode* next;
}SListNode;
void SListInit(SListNode** phead);
void SListDestory(SListNode* phead);
SListNode* BuySListNode(SLTDataType x);
void SListPushFront(SListNode** phead, SLTDataType x);
void SListPopFront(SListNode** phead);
SListNode* SListFind(SListNode* phead, SLTDataType x);
void SListInsertAfter(SListNode* pos, SLTDataType x);
void SListEraseAfter(SListNode* pos);
void SListRemoveA(SListNode** phead, SLTDataType x);
void SListPrint(SListNode* phead);
void TestSList();
#endif
具體功能實(shí)現(xiàn)如下:
void SListInit(SListNode** pphead)
{
*pphead = NULL;
}
SListNode* BuySListNode(SLTDataType x)
{
SListNode* res = (SListNode*)malloc(sizeof(SListNode));
res->data = x;
res->next = NULL;
return res;
}
void SListPushFront(SListNode** pphead, SLTDataType x)
{
SListNode* tmp = BuySListNode(x);
tmp->next = *pphead;
*pphead = tmp;
}
void SListPopFront(SListNode** pphead)
{
SListNode* tmp = (*pphead)->next;
free(*pphead);
*pphead = tmp;
}
void SListInsertAfter(SListNode* pos, SLTDataType x)//后插
{
SListNode* tmp = BuySListNode(x);
tmp->next = pos->next;
pos->next = tmp;
}
// 在pos的前面進(jìn)行插入
void SListEraseAfter(SListNode* pos)//后刪
{
SListNode* tmp = pos->next;
if (tmp == NULL)
{
return;
}
pos->next = tmp->next;
free(tmp);
}
SListNode* SListFind(SListNode* phead, SLTDataType x)//查找
{
SListNode* tmp;
for (tmp = phead; tmp; tmp = tmp->next)
{
if (tmp->data == x)
{
return tmp;
}
}
return NULL;
}
void SListRemoveA(SListNode** pphead, SLTDataType x)//刪除某個(gè)值的所有節(jié)點(diǎn)
{
SListNode* tmp;
while(*pphead&&(*pphead)->data==x)
{
SListPopFront(pphead);
}
for (tmp = *pphead;tmp&&tmp->next; )
{
if (tmp->next->data==x)
{
SListEraseAfter(tmp);
}
else
{
tmp = tmp->next;
}
}
}
void SListPrint(SListNode* phead)
{
SListNode* tmp;
for (tmp = phead; tmp; tmp = tmp->next)
{
printf("%d->", tmp->data);
}
if (tmp == NULL)
{
printf("NULL");
}
printf("\n");
}
void SListDestory(SListNode* phead)//方法一:不斷后刪(此處),方法二:不斷頭刪
{
while (phead->next)
{
SListEraseAfter(phead);
}
free(phead);
//phead = NULL;
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。