上一篇的头插法书写有误,在此更正
//create by yu #include "stdio.h" #include "stdlib.h" typedef struct node{ int element; struct node *next; }node,*linklist; linklist insertfromhead(int number){ linklist head=(linklist)malloc(sizeof(node)); head->next=NULL; for(int i=0;i<number;i++){ linklist n=(linklist)malloc(sizeof(node)); printf("please input the %dth number",(i+1)); scanf("%d",&(n->element)); n->next=head->next; head->next=n; } return head; } void display(linklist head){ linklist temp=head; while(temp->next){ temp=temp->next; printf("%d ",temp->element); } } int main(){ linklist head=insertfromhead(5); display(head); return 0; }