is there a better way to optimise this?
I have written an in_order_list function, was just wondering if there is a better way to do it, mine seems to work fine through testing. It just looks a bit long, what do you think:
Code:
list_t
*insert_in_order (list_t *list, data_t value)
{
node_t *new, *curr, *prev;
new = (node_t *) malloc (sizeof (node_t));
new->next = NULL;
new->data = value;
curr = list->head;
if (curr == NULL) /*We have the first entry*/
{
list->foot = list-> head = new;
return list;
}
if (curr->data > value)
{
new->next = curr;
list->head = new;
return list;
}
else
while (curr->next !=NULL)
{
if (curr->data < value)
{
prev = curr;
curr = curr->next;
}
if (curr->data > value)
{
new->next = curr;
prev->next = new;
greturn list;
}
}
curr->next = new;
return list;
}