#include<stdio.h>
#include<malloc.h>
struct node
{
    int data;
    struct node *link;
};
void create(struct node **,int);
void display(struct node *);
struct node* reverselist(struct node **);
int main()
{
    struct node *p,*q;
    p=NULL;
    create(&p,1);
    create(&p,2);
    create(&p,3);
    create(&p,4);
    create(&p,5);
    printf("before:\n");
    display(p);
    q=reverselist(&p);
    printf("\n after");
    display(q);
    return 0;
}
void create(struct node **q,int num)
{
    struct node *temp,*r;
    if(*q==NULL)
    {
        temp=malloc(sizeof(struct node));
        temp->data=num; temp->link=NULL;
        *q=temp;
    }
    else
    {
        temp=*q;
        while(temp->link!=NULL)
            temp=temp->link;
        r=malloc(sizeof(struct node));
        r->data=num;r->link=NULL;
        temp->link=r;
    }
}
void display(struct node *p)
{
    while(p!=NULL)
    {printf(" %d,",p->data); p=p->link;}
}
struct node* reverselist(struct node **q)
{
    struct node *p;
    p=(*q)->link;
     if(q==NULL) 
      return NULL;
     if(p==NULL)
      return (*q);
    (*q)->link=NULL;
    struct node *list=recursivelist(&p);
    p->link=*q;
    return list;
}
