C語言數(shù)據(jù)結(jié)構(gòu)單鏈表及其基本功能實(shí)現(xiàn)-創(chuàng)新互聯(lián)

頭文件如下:

成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、永昌網(wǎng)絡(luò)推廣、小程序定制開發(fā)、永昌網(wǎng)絡(luò)營銷、永昌企業(yè)策劃、永昌品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供永昌建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:muchs.cn
#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元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

分享文章:C語言數(shù)據(jù)結(jié)構(gòu)單鏈表及其基本功能實(shí)現(xiàn)-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://muchs.cn/article0/deisoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航定制網(wǎng)站、網(wǎng)站設(shè)計(jì)、面包屑導(dǎo)航移動(dòng)網(wǎng)站建設(shè)、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)