1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| list l = (list) malloc(sizeof(struct list));
l -> val = val;
if(the_list == NULL || the_list -> val >= val)
{
/* insert the element first */
l -> next = the_list;
the_list = l;
} else {
list q = the_list;
list p = q -> next;
for(; p && p -> val < val; q = p, p = p -> next)
;
l -> next = p;
q -> next = l;
}
|