#include <stdio.h>
#include <malloc.h>
struct lnode *creat(int n);
struct lnode {
int data;
struct lnode *next;
};
int main() {
int n;
struct lnode *q;
printf("输入你想创建的节点数:\n");
scanf("%d", &n);
q = creat(n);
while (q) {
printf("%d", q->data);
q = q->next;
}
return 0;
}
struct lnode *creat(int n) {
int i;
struct lnode *p;
int a;
struct lnode *head = (struct lnode *)malloc(sizeof(struct lnode));
head->next = NULL;
for (i = n - 1; i >= 0; i--) {
p = (struct lnode *)malloc(sizeof(struct lnode));
scanf("%d", &a);
p->data = a;
p->next = head->next;
head->next = p;
}
return head;
}