void sort(struct node **s2) {
struct node *x, *y;
x = *s2;
char *str;
while (x != NULL) {
y = x->n;
while (y != NULL) {
if (strcmp(x->name, y->name) > 0) {
strcpy(str, x->name);
strcpy(x->name, y->name);
strcpy(y->name, str);
}
y = y->n;
}
x = x->n;
}
}
这显示运行时错误。 我不知道什么是错 我相信排序是正确的 它的选择排序 我节点的结构是:运行时错误排序字符串的链接列表
struct node {
char *name;
struct node *n;
};
它显示运行时错误。
你的排序功能无法编译,你错过了一个'}' – Caw
哦,即时对不起,我错过了一个}在这里...我已经在我的原始程序} – Ali
你的算法是一个不稳定的sele变体ction排序。它的时间复杂度是** O(N^2)**。尝试并实现合并排序,这是一种更有效的算法,其最坏情况下的时间复杂度为** O(N.log(N))**。 – chqrlie