#include
using namespace std;
class Node {
public:
Node(int d, Node* next1 = NULL):data(d), next(next1){}
int data;
Node* next;
};
void printList(Node* n)
{
while (n != NULL) {
cout data next;
}
cout next == NULL)
return;
Node* x = w, *y = x->next, *z = y->next;
x->next = NULL;
while(y!=NULL){
y->next = x;
x = y;
y = z;
z = z == NULL ? NULL : z->next;
}
}
int main()
{
Node* x = new Node(4);
Node* y = new Node(3, x);
Node* z = new Node(2, y);
Node* w = new Node(1, z);
printList(w);
reverseList(w);
printList(x);
return 0;
}