How to revert a linked list
Anonymous
void reverse() { // Initialize current, previous and next pointers Node* current = head; Node *prev = NULL, *next = NULL; while (current != NULL) { // Store next next = current->next; // Reverse current node's pointer current->next = prev; // Move pointers one position ahead. prev = current; current = next; } head = prev; }
Check out your Company Bowl for anonymous work chats.