#include <iostream>
struct Node{
Node(): next(NULL){}
Node *next;
std::string data;
};
void printlist(Node* l){
while(l){
std::cout<<l->data<<std::endl;
l = l->next;
}
std::cout<<"----"<<std::endl;
}
void reverse(Node*& l)
{
Node* prev = NULL;
while(l){
auto next = l->next;
l->next = prev;
prev=l;
l=next;
}
l = prev;
}
int main() {
Node s,t,u,v;
s.data = "1";
t.data = "2";
u.data = "3";
v.data = "4";
s.next = &t;
t.next = &u;
u.next = &v;
Node* ptr = &s;
printlist(ptr);
reverse(ptr);
printlist(ptr);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IE5vZGV7CglOb2RlKCk6IG5leHQoTlVMTCl7fQoJTm9kZSAqbmV4dDsKCXN0ZDo6c3RyaW5nIGRhdGE7Cn07Cgp2b2lkIHByaW50bGlzdChOb2RlKiBsKXsKCXdoaWxlKGwpewoJCXN0ZDo6Y291dDw8bC0+ZGF0YTw8c3RkOjplbmRsOwoJCWwgPSBsLT5uZXh0OwoJfQoJc3RkOjpjb3V0PDwiLS0tLSI8PHN0ZDo6ZW5kbDsKfQoKdm9pZCByZXZlcnNlKE5vZGUqJiBsKQp7CglOb2RlKiBwcmV2ID0gTlVMTDsKCXdoaWxlKGwpewoJCWF1dG8gbmV4dCA9IGwtPm5leHQ7CgkJbC0+bmV4dCA9IHByZXY7CgkJcHJldj1sOwoJCWw9bmV4dDsKCX0KCWwgPSBwcmV2Owp9CgppbnQgbWFpbigpIHsKCU5vZGUgcyx0LHUsdjsKCXMuZGF0YSA9ICIxIjsKCXQuZGF0YSA9ICIyIjsKCXUuZGF0YSA9ICIzIjsKCXYuZGF0YSA9ICI0IjsKCXMubmV4dCA9ICZ0OwoJdC5uZXh0ID0gJnU7Cgl1Lm5leHQgPSAmdjsKCU5vZGUqIHB0ciA9ICZzOwoJcHJpbnRsaXN0KHB0cik7CiAgICByZXZlcnNlKHB0cik7CiAgICBwcmludGxpc3QocHRyKTsKCXJldHVybiAwOwp9Cg==