代码如下:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
typedef struct linklist {
int data;
struct linklist* next;
}node;
int main(void) {
node* head = (node*)malloc(sizeof(node));
head->next = NULL;
node* p;
p=head;
int n;
printf("请输入链表的长度:\n");
scanf("%d", &n);
printf("请输入元素:\n");
for (int i = 0; i < n; i++) {
node* s = (node*)malloc(sizeof(node));
scanf("%d", &s->data);
p->next = s;
s->next = NULL;
p = s;
}
p = head;
while (p->next != NULL) {
printf("%5d", p->next ->data);
p = p->next;
}
}