I have successfully implemented the 2 pointers solution using this code:
void list_reverse(t_list **begin_list)
{
t_list *new_root;
t_list *root;
t_list *next;
new_root = 0;
root = *(begin_list);
while (root)
{
next = root->next;
root->next = new_root;
new_root = root;
root = next;
}
*begin_list = new_root;
}
Which works fine - at least according to my tests. Now I want to try to reverse a linked list using only a single pointer, without return, so I tried to convert my code to void list_reverse(t_list *begin_list), but of course the *begin_list = new_root doesn't work, because I can't change begin_list. The rest seems to work though.
How can I modify begin_list without a double pointer?
Edit: Structure is :
typedef struct s_list
{
struct s_list *next;
void *data;
} t_list;