栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

数据结构1.0(c语言)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

数据结构1.0(c语言)

线性链表及其应用

1.线性链表节点ADT定义

typedef int ElmType;
typedef  struct node{
    ElmType data;
    struct node* next;
}Node;

typedef enum ret_type {ERROR=-1,OK = 0} Status;

typedef Node* linkedList;

1.2 产生一个节点

//产生一个节点
linkedList node_create(ElmType data)
{
    linkedList node=(linkedList)malloc(sizeof (Node));
    node->data=data;
    node->next=NULL;
    return node;
}

1.3  打印链表

//打印链表
Status list_print(linkedList head)
{
    if(head==NULL)
    {
        return ERROR;
    }
    linkedList ptr = head->next;
    while (ptr)
    {
        printf("%5d",ptr->data);
        ptr=ptr->next;
    }
    printf(("n"));
    return  OK;
}

1.4在链表头部插入新的元素

//在链表头部插入新的元素
Status list_push_front(linkedList head,ElmType data)
{
    if(head==NULL)
    {
        return  ERROR;
    }
    if (head->next==NULL)
    {
        linkedList newNode= node_create(data);
        head->next=newNode;
    }
    else
    {
        linkedList newNode= node_create(data);
        newNode->next=head->next;
        head->next=newNode;
    }
}

1.5  在链表头部删除元素

//在链表头部删除元素
Status list_pop_front(linkedList head,ElmType* data)
{
    if(head==NULL)
    {
        return  ERROR;
    }
    else
    {
        linkedList ptr=head->next;
        head->next=ptr->next;
        printf("%d",ptr->next);
        free(ptr);

    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/676764.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号