#include<stdio.h>
#include<malloc.h>
typedef int elemtype;
typedef struct node
{
elemtype data;
struct node *next;
}
linklist;
linklist *creatlist(int n)
{
int x,k;
linklist *head,*r,*p;
p=(linklist *)malloc(sizeof(linklist));
head=p;
p->next=NULL;
r=p;
for(k=1;k<=n;k++)
{
printf("input value :\n");
scanf("%d",&x);
p=(linklist *)malloc(sizeof(linklist));
p->data=x;
p->next=NULL;
r->next=p;
r=r->next;
}
return head;
}
linklist *fun(linklist *head)
{
linklist *p,*r,*q;
p=head->next;
q=head;
q=p;
p=p->next;
q->next=NULL;
while(p)
{
r=q;
q=p;
p=p->next;
q->next=r;
}
head->next=q;
return head;
}
void main()
{
linklist *head,*p;
int n,i,x;
printf("input the length of the list :\n");
scanf("%d",&n);
head=creatlist(n);
head=fun(head);
printf("output the list :\n");
p=head->next;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
getch();
}