有大佬知道为什么我的链表输出不正确吗
程序代码:
#include <stdio.h> #include <stdlib.h> typedef struct _node{ int value; struct _node *previous; struct _node *next; } Node; int main(void){ Node *head=NULL; Node *tail=NULL; int j=1; for(int number;scanf("%d",&number)==1&&number!=-1;){ Node *Last=head; if(j==1){ head=(Node *)malloc(sizeof (Node)); head->value=number; head->next=NULL; head->previous=NULL; j++; break; } else{ for(;Last;Last=Last->next); Node *p=(Node *)malloc(sizeof (Node)); Last->next=p; p->value=number; p->next=NULL; p->previous=Last; tail=p; } } for(Node *i=head;i;i=i->next){ printf( "%d\t", i->value ); } for(Node *k=tail;k;k=k->previous){ printf( "%d\t", k->value ); } return 0; }