单向链表哪里有问题?谢谢
程序代码:
#include<stdio.h> #include<stdlib.h> int main() { struct new { int num; struct new *next; }; struct new *first=NULL; struct new *current=NULL; struct new *last=NULL; first=malloc(sizeof(struct new)); current=malloc(sizeof(struct new)); last=malloc(sizeof(struct new)); printf("please input the first number:"); setbuf(stdin,NULL); scanf("%d",&first->num); current=first->next; while(1) { scanf("%d",¤t->num); if(current->num==-1) //输入-1表示结束 {last->next==NULL;break;} last=current; current=malloc(sizeof(struct new)); last->next=current; current->next=NULL; } current=first; do { printf("%d\n",current->num); current=current->next; } while(current); }