But what are you trying to achieve by mallocing a new node here?
The first node on your sorted list (high_head) should be set to NULL, so that it acts as the terminator.
<edit> oh, and get rid of this part:
Code:
high_head->prev = high_head;
high_head->next = high_head;
</edit>
Now, assuming that your add and delete functions are fine I think this should work.
Another approach would be to simply relink you list. This would avoid all the adding and deleting. Basically you do not have to create any new nodes to sort your list; its simply a matter of changing where the links point to. to give you an idea of how you could go about it in pseudo code:
Code:
Set the head of the new (sorted) list to NULL
While there are nodes on the old (unsorted) list
Loop through each node on unsorted list
Store the node before the smallest result
Store the smallest result
Store the node after the smallest result
Link node from before smallest result to node after smallest result
Link node from after smallest result to node before smallest result
Add orphaned smallest result node to the new (sorted) list
but, considering where you are its probably easiest to try and get what you have to work.
Edit2: oh, and ignore my last post above; it was an accident.