下面的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