Rotate image (square matrix) by 90 deg
Tue, 06 May 2025
void printReverse(Node* head)
{
// terminating condition
if(head == NULL)
return;
printReverse(head->next);
printf("%d ", head->data);
}
But the above function does not change the structure of the linked list, it just print it in reverse order. So it is not reversing the linked list but just printing it. (We have already covered this topic earlier)
Function to reverse will also be on the same lines.
void recursiveReverse( Node** head)
{
Node* first;
Node* rest;
if (*head == NULL)
return;
first = *headRef; // suppose first = {1, 2, 3}
rest = first->next; // rest = {2, 3}
if (rest == NULL)
return;
recursiveReverse(&rest);
first->next->next = first;
first->next = NULL;
*head = rest;
}
Tue, 06 May 2025
Tue, 06 May 2025
Tue, 06 May 2025
Leave a comment