网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C语言数据结构单链表及其基本功能实现-创新互联

头文件如下:

成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、成都网站设计、永昌网络推广、小程序定制开发、永昌网络营销、永昌企业策划、永昌品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;成都创新互联为所有大学生创业者提供永昌建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com
#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

具体功能实现如下:

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的前面进行插入
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)//删除某个值的所有节点
{
    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;
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:C语言数据结构单链表及其基本功能实现-创新互联
标题网址:http://bjjierui.cn/article/deisoo.html

其他资讯