1. ## Please explain help me!!

This is a code for inverting a linked link.But I just understand a little.Please explain it clearly help me.
Code:
``` node *inverting (list &first, list &last)
{
node *tmp;
if (first != NULL)
{
if ((first)->next != NULL)
{
tmp= inverting (first->next,last);
(last)->next = first;
last = first;
(last)->next = NULL;
first = tmp;
}
return first;
}
else
return NULL;
}```

2. Well it might be easier to follow if it were indented properly.

3. Code:
```node *inverting (list &first, list &last)
{
node *tmp;
if (first != NULL)
{
if ((first)->next != NULL)
{
tmp= inverting (first->next,last);
(last)->next = first;
last = first;
(last)->next = NULL;
first = tmp;
}
return first;
}
else
return NULL;
}```
Before i answer this question, have u got any idea of how recursion function works. If not look through it and then try looking at this code.

ssharish2005

4. Originally Posted by KySiRo
Code:
`node *inverting (list &first, list &last)`
Since when does C support passing by reference?!

5. Originally Posted by zacs7
Since when does C support passing by reference?!
Good question, realizing that this thread should now be moved to C++

ssharish2005

6. Agreed - moved.

7. >> have u got any idea of how recursion function works
It just calls the function again. To get an idea, copy and paste that function 10 times and give it 10 different names (append like inverting1, inverting2, inverting3, etc). Then, have inverting1 call inverting2, and have inverting2 call inverting3, and so on. Have the outside code that calls it call inverting1 to start it off.

If you understand how the code works at that point (it is just one function calling another), then you understand recursion. The only difference is that the functions are only written once.