#include<iostream>
using namespace std;
struct node
  {
int data;
struct node * next;
};
node* reverse(node * head)
  {
node * p1,*p2,*p3;
p1=head;
p2=p1->next;
while(p2!=NULL)
 {
p3=p2->next;
p2->next=p1;
p1=p2;
p2=p3;
}
head->next=NULL;
head=p1;
return head;
}
node * makeNode()
  {
int n;
node * head,*p,*q;
head=(node*)malloc(sizeof(node));
p=head;
cin>>n;
for(int i=1;i<n;i++)
 {
scanf("%d",&p->data);
q=(node*)malloc(sizeof(node));
p->next=q;
p=q;
}
scanf("%d",&p->data);
p->next=NULL;
return head;
}
void print(node *head)
  {
while(head!=NULL)
 {
cout<<head->data<<endl;
head=head->next;
}
}
int main()
  {
print(reverse(makeNode()));
return 0;
}


|