题解 | #牛牛的单向链表#

牛牛的单向链表

https://www.nowcoder.com/practice/95559da7e19c4241b6fa52d997a008c4

#include <stdio.h>
#include <stdlib.h>
typedef int data_t ;

//定义节点
typedef struct node
{
    data_t date;
    struct node *next;
}listnode,*linklist;

//表头创建
linklist list_create()
{
    linklist H ;
    H = (linklist)malloc(sizeof(listnode));
    if(H == NULL)
    {
        printf("malloc is NULL");
        return NULL;
    }
    H->date = 0;
    H->next = NULL;
    return H; 
}

//表未插入
void list_insert(linklist H)
{
    linklist L = (linklist)malloc(sizeof(listnode));
    linklist h;
    h = H;
    if(L == NULL)
    {
        printf("L_malloc is NULL");
        return ;
    }
    int n;
    scanf("%d",&n);
    L->date = n;
    L->next = NULL;
    while(h->next!=NULL)
    {
        h = h->next; 
    }
    h->next = L;
}

//打印单链表
int list_show(linklist H)
{
    linklist h = H->next;
    while (h->next != NULL) {
        printf("%d ",h->date);
        h = h->next;
    }
    return 0;
}


int main() {
    int n, i;
    linklist H= list_create();
    scanf("%d",&n);
    for(i = 0;i<=n;i++)
        list_insert(H);
    list_show(H);
    return 0;
}

全部评论

相关推荐

06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务