void linklist::sort(linklist *l)
{
cout << "链表开始升序" << endl;
linklist *k = l, *t = l;
while (t->next != NULL)//t相当于i
{
k = l;//这里要保证每次循环都是没有修改过的链表
while (k->next != NULL)//k相当于j
{
if (k->data > k->next->data)
{
char p;
p = k->data;
k->data = k->next->data;
k->next->data = p;
}
k = k->next;
}
t = t->next;
}
watch(l);
};
算法-链表版冒泡
最新推荐文章于 2024-08-30 11:28:00 发布