#include<stdio.h>
#include<stdlib.h> struct node { int date; struct node *next; }; int main (void){ struct node *p,*pl, *head; head=p=(struct node *)malloc(sizeof(struct node)); scanf("%d",&p->date);/*頭節(jié)點數(shù)據(jù)成員*/ while(p->date!=-1){ pl=p; p=(struct node *)malloc(sizeof(struct node)); scanf("%d",&p->date);/*中間節(jié)點成員*/ pl->next=p; } p->next=NULL; p=head;/*鏈表顯示*/ while(p->next!=NULL){ printf("%d ",p->date); p=p->next; } //printf("%d ",p->date);/*顯示終止字符-1*/ } |
|