题解 | #牛牛的单向链表#
牛牛的单向链表
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;
}

查看13道真题和解析