C语言正序单链表爱吃窝窝头2023-11-302023-11-30#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}node;node *l,*t;void initlist(){ l=(node *)malloc(sizeof (node)); if (!l) exit(0); l->next=NULL; t=l;}void creat(int n){ node *p; int i; for (i=1;i<=n;i++) { p=(node *)malloc(sizeof (node)); if (!p) exit(0); scanf("%d",&p->data); p->next=NULL; t->next=p; t=p; } }void output(){ node *p; p=l->next; while(p) { printf("%d ",p->data); p=p->next; } printf ("\n");}void main(){ int n; initlist(); printf("请输入链表长度:"); scanf("%d",&n); printf("请输入元素:"); creat(n); printf("输出结果:\n"); output();}