#include <iostream> #include <vector> #include <string> using namespace std; struct Node { int data; Node * next; }; Node * reverseList(Node * head) { Node * pre = nullptr; Node * cur = head; Node * next = nullptr; while (cur) { next = cur->next; cur->next = pre; pre = cur; cur = next; } return pre; } int main() { Node * a = new Node();; a->data = 1; Node * b = new Node(); b->data = 2; a->next = b; b->next = nullptr; Node * head = reverseList(a); while (head) { cout<<head->data<<endl; head = head->next; } cout << "hello" << endl; return 0; }