node *bubbleSortList(node *head)
{
if (head == NULL || head->next == NULL) return head;
node *p = NULL;
bool isChange = true;
while (p != head->next->next && isChange)
{
node *q = head->next;
isChange = false; //标志当前这一轮中又没有发生元素交换,如果没有则表示数组已经有序
for (; q->next && q->next != p; q = q->next)
if (q->data > q->next->data)
swap(q->data, q->next->data), isChange = true;
p = q;
}
return head;
}
c++ 链表排序
猜你喜欢
转载自blog.csdn.net/qq_43041976/article/details/90113640
今日推荐
周排行