i ammended the code and have thusfar untested :
Code:
list_t
*insert_in_order (list_t *list, int value) {
node_t *new, *ptr;
new = malloc(sizeof(*new));
assert(list!=NULL);
new->data=value;
ptr=list->head;
if (ptr->data<value)
/*must be smaller than the head, insert it at the head and stop*/
{
list = insert_at_head(list, value);
}
while (ptr!=NULL)
{
if (ptr->data==value)
/*equal values, so it doesn't matter if it is put in before or after, we'll do it before*/
{
new->next=ptr->next;
ptr->next=new;
break;
}
if (ptr->data<value && ptr->next->data>value)
/*must be the right place to insert*/
{
new->next=ptr->next;
ptr->next=new;
break;
}
else
{
ptr = ptr->next;
}
}
/*Reached end of the line wihtout a larger value ahead, insert at foot*/
list = insert_at_foot(list, value);
return list;
}