You are viewing a single comment's thread. Return to all comments →
The first two if statements are covered by the while loop. slightly better version (in C++):
SinglyLinkedListNode* reverse(SinglyLinkedListNode* head) { SinglyLinkedListNode* prevNode = nullptr; SinglyLinkedListNode* currNode = head; SinglyLinkedListNode* nextNode = nullptr; while(currNode != nullptr){ nextNode = currNode->next; currNode->next = prevNode; prevNode = currNode; currNode = nextNode; } head = prevNode; return head; }
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse a linked list
You are viewing a single comment's thread. Return to all comments →
The first two if statements are covered by the while loop. slightly better version (in C++):