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

牛牛的单向链表

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

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

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

Node* creactNode(int data){
    Node* newNode=(Node*)malloc(sizeof(Node));
    newNode->data=data;
    newNode->next=NULL;
    return newNode;
}

int main() {
    int n;
    scanf("%d",&n);
    int array[n];
    for (int i=0; i<n; i++) {
    scanf("%d",&array[i]);
    }

    Node* head=(Node*)malloc(sizeof(Node));
    head->data=array[0];
    head->next=NULL;

    Node* temp=head;
    for (int i=1; i<n; i++) {
    temp->next=creactNode(array[i]);
    temp=temp->next;
    }

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

    return 0;
}

全部评论

相关推荐

真烦好烦真烦:牛友太有实力了
点赞 评论 收藏
分享
见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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