#include<iostream>
using namespace std;
struct Node{
int val;
Node* next;
Node(int v):val(v),next(NULL){}
};
Node * reverseList(Node* head){
Node* pre = NULL;
Node* cur = head;
Node* cnext = NULL;
while(cur){
cnext = cur->next;
cur->next = pre;
pre = cur;
cur = cnext;
}
return pre;
}
int main(){
Node* head = new Node(1);
head->next = new Node(2);
head->next->next = new Node(3);
Node *ans = reverseList(head);
while(ans){
cout<<ans->val<<" ";
ans = ans->next;
}
return 0;
}