1 #include <iostream> 2 #include <cstdlib> 3 using namespace std; 4 typedef struct node 5 { 6 int date ; 7 node *pri; 8 node *next; 9 }*linklist,listnode; 10 linklist creatlist(int num) 11 { 12 linklist head=NULL,temp=NULL,tail=NULL; 13 int i; 14 for(i=0;i<num;i++) 15 { 16 if(head==NULL) 17 { 18 head=(linklist)malloc(sizeof(listnode)); 19 cin>>head->date; 20 head->pri=NULL; 21 tail=head; 22 } 23 else 24 { 25 temp=(linklist)malloc(sizeof(listnode)); 26 cin>>temp->date; 27 temp->pri=tail; 28 tail->next=temp; 29 tail=temp; 30 tail->next=NULL; 31 32 } 33 } 34 return head; 35 } 36 linklist outputlist(linklist head) 37 { 38 linklist p=head,tail; 39 while(p!=NULL) 40 { 41 cout<<p->date<<' '; 42 tail=p; 43 p=p->next; 44 } 45 return tail; 46 } 47 void _outputlist(linklist tail) 48 { 49 linklist p=tail; 50 while(p!=NULL) 51 { 52 cout<<p->date<<' '; 53 p=p->pri; 54 } 55 } 56 int main() 57 { 58 linklist head,tail; 59 int num; 60 cin>>num; 61 head=creatlist(num); 62 tail=outputlist(head); 63 cout<<endl; 64 _outputlist(tail); 65 }