#include using namespace std; struct Node { int data; Node* next; }; // Function to create a new node for a linked list Node* create_node(int value) { Node* newNode = new Node; newNode->data = value; newNode->next = nullptr; return newNode; } // Function to reverse a linked list Node* reverse_list(Node* head) { Node* prev = nullptr; Node* current = head; Node* nextNode = nullptr; while (current != nullptr) { nextNode = current->next; // Store the next node current->next = prev; // Reverse the link // Move pointers to the next positions prev = current; current = nextNode; } return prev; // The new head of the reversed list } // Function to display the linked list void display_list(Node* head) { Node* current = head; while (current != nullptr) { cout << current->data << " "; current = current->next; } cout << endl; } int main() { Node* head = nullptr; // Initializing an empty linked list // Inserting elements into the linked list insert_into_list(head, 5, 0); insert_into_list(head, 10, 0); insert_into_list(head, 15, -1); insert_into_list(head, 20, 1); head = reverse_list(head); display_list(head); }