I'm trying to brush up on my C and have been reviewing data structures and pointer manipulation. Can someone please explain to me why it is necessary to use a pointer to a pointer for head in this linked list reverse function? Since head is always dereferenced once (*head) in the function, couldn't we just accept a normal Node* as an argument to this function and forgo the dereferencing? Thanks in advance!
struct Node{
int key;
struct Node *next;
};
struct Node* reverse(struct Node** head){
Node *parent = *head;
Node *me = parent->next;
Node *child = me->next;
parent->next = NULL;
while(child) {
me->next = parent;
parent = me;
me = child;
child = child->next;
}
me->next = parent;
*head = me;
return *head;
}