reverse linked list using recursion

PHOTO EMBED

Fri Jul 19 2024 04:13:46 GMT+0000 (Coordinated Universal Time)

Saved by @vishnu_jha #c++ #dsa #linkedlist #reverselinkedlist #recursion

// it will return the head of the reversed linked list
node* reverse1 (node* head) {
  // base case
  if (head == NULL || head -> next == NULL) {
    return head;
  }
  node* chotaHead = reverse1(head -> next) {
    head -> next -> next = head;
    head -> next = NULL;

    return chotaHead;
  }
}
content_copyCOPY

https://youtu.be/vqS1nVQdCJM