The following code works fine when head is sent as a parameter to it. As I am new to C, I couldn't understand how it works. Help me out please.
struct node *recursiveReverseLL(struct node *list)
{
struct node *revHead;
if (list == NULL || list->link == NULL)
{
return list;
}
revHead = recursiveReverseLL(list->link);
list->link->link = list;
list->link = NULL;
return revHead;
}
I dont know how the links are provided using those recursive calls. ie) if the links are as,
1 -> 2 -> 3 -> 4
then hw is it changed as,
4 -> 3 -> 2 -> 1
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…