#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 ) ;
display( p) ;
q= reverselist( & p) ;
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;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8bWFsbG9jLmg+CnN0cnVjdCBub2RlCnsKICAgIGludCBkYXRhOwogICAgc3RydWN0IG5vZGUgKmxpbms7Cn07CnZvaWQgY3JlYXRlKHN0cnVjdCBub2RlICoqLGludCk7CnZvaWQgZGlzcGxheShzdHJ1Y3Qgbm9kZSAqKTsKc3RydWN0IG5vZGUqIHJldmVyc2VsaXN0KHN0cnVjdCBub2RlICoqKTsKaW50IG1haW4oKQp7CiAgICBzdHJ1Y3Qgbm9kZSAqcCwqcTsKICAgIHA9TlVMTDsKICAgIGNyZWF0ZSgmcCwxKTsKICAgIGNyZWF0ZSgmcCwyKTsKICAgIGNyZWF0ZSgmcCwzKTsKICAgIGNyZWF0ZSgmcCw0KTsKICAgIGNyZWF0ZSgmcCw1KTsKICAgIHByaW50ZigiYmVmb3JlOlxuIik7C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