The following C code doesn't work (it just clears the list):
/* Takes linkedlist of strings */
static int insertSort (linkedlist *list) {
linkedlist sorted;
void *data;
node *one, *two, *newnode;
unsigned int comp, x;
removeHeadLL (list, &data);
initLL (&sorted);
addHeadLL (&sorted, data);
while (list->count) {
removeHeadLL (list, &data);
two = sorted.head;
x = 0;
for (comp = strcomp (data, two->data) ; comp > 1 && x < sorted.count ; x++) {
one = two;
two = two->next;
}
if (x) {
newnode = malloc (sizeof(node));
newnode->next = two;
newnode->data = data;
one->next = newnode;
}
else {
addHeadLL(&sorted, data);
}
(sorted.count)++;
}
destroythis (list);
list = &sorted;
return 0;
}
Full context: http://buu700.res.cmu.edu/CMU/15123/6/