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

牛牛的单向链表

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-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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