void BubbleSortNode(SListNode *&pHead)//单链表排序
{
assert(pHead);
SListNode *tail = NULL;
int Bool = 0; //若没有进行交换提前返回
while (tail!=pHead->next)
{
Bool = 0;
SListNode *tmp = pHead;
SListNode *tmpnext = tmp->next;
while (tmp->next != tail)
{
if (tmp->data > tmpnext->data)
{
DataType x = tmp->data;
tmp->data = tmpnext->data;
tmpnext->data = x;
Bool = 1;
}
tmp = tmp->next;
tmpnext = tmpnext->next;
}
if (Bool == 0)// 已排好序提前返回
return;
tail = tmp;
}
}
笔试,面试,C/C++,数据结构单链表排序(改进冒泡排序)
最新推荐文章于 2022-09-23 16:10:47 发布