Code that can be compiled to executable can be found on ideone
https://ideone.com/uT1WvV
It works only for singly linked list
The goal of this task is to set previous poiners in that way
the function will be able to sort doubly linked list
I tried to do this on my own but i failed
I changed insert function
1 2 3 4 5 6 7 8 9 10 11
|
void tailins(node *r,node **first,node **last)
{
if((*first) == NULL)
(*first) = r;
else
{
(*last)->next = r;
r->prev = (*last)
}
(*last) = r;
}
|
and tried to insert instruction
1 2
|
if(x->next != NULL)
x->next->prev = x;
|
in different places in the code
but it does not work correctly
Duthomhas it looks like you dont want help me
(and others when they will have the same problem)
The only one thing we should do is to set prev pointers correctly
so why rewrite code once again
"And moving the data is usually better..."
Not true , it is visible especially if we have many fields in the data part of the node
If we allow moving data you will be able to copy and paste geeks solution