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

牛牛的单向链表

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

#include <stdio.h>
#include <stdlib.h>

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

int main() {
    int count, value;
    scanf("%d", &count);

    Node* head = (Node*)malloc(sizeof(Node));
    Node* current = head;

    for (int i = 0; i < count; i++) {
        scanf("%d", &value);
        current->data = value;

        current->next = (Node*)malloc(sizeof(Node));
        current = current->next;
    }

    current = head;

    while (current->next != NULL) {
        printf("%d ", current-> data);
        current = current->next;
    }


    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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