From 6afef2d89ab32bcd3b494fb6bc3282ee50e3d694 Mon Sep 17 00:00:00 2001 From: Sujaybiradar25 Date: Fri, 19 Feb 2021 21:52:47 +0530 Subject: [PATCH] Reverse a linked list recursively Added code. --- C++/Linked List/Reverse a linked list recursively.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/C++/Linked List/Reverse a linked list recursively.cpp b/C++/Linked List/Reverse a linked list recursively.cpp index c98b38cf..3e0048b0 100644 --- a/C++/Linked List/Reverse a linked list recursively.cpp +++ b/C++/Linked List/Reverse a linked list recursively.cpp @@ -1,3 +1,8 @@ -void reverse_list(list_node *head){ - list_node * +list_node* reverse_list(list_node *head){ + if(head == NULL || head->next == NULL) + return head; + list_node* temp = reverse_list(head->next); + head->next->next = head; + head->next = NULL; + return temp; }