I am trying to figure out how to recursively shift a linked list right once. I feel like I'm on the right track, but I can't seem to fully solve it.
Here is my code currently:
struct node *shift(struct node *node, struct node *head) {
if (node == NULL || node->next == NULL) {
return node;
}
if (node->next->next == NULL) {
struct node *temp = node->next;
temp->next = head;
node->next = NULL;
return temp;
}
node->next = listShift(node->next, head);
return temp;
}
I was hoping to try and do it without using the extra head parameter in the function, but I thought I'd try and figure it out with the extra parameter first.