下面的C代碼不起作用(它只是清除列表):插入排序調試幫助
/* 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;
}
完全上下文:http://buu700.res.cmu.edu/CMU/15123/6/
「下面的C代碼不起作用:」 - 啊!什麼不行? – 2010-10-29 01:35:57
對不起,我有點含糊,因爲我有點急。結果是,我最終得到了一個空白鏈表 - 不知道這樣做會發生什麼。 – 2010-10-29 01:38:42