Node *Reverse(Node *&head) { if (head == NULL || head->next == NULL) return head; Node *NewHead = Reverse(head->next); head->next->next = head; head->next = NULL; return NewHead; } //in main the previous head becomes the last node int main(){ Node*newHead=Reverse(head); print(newhead); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter