24-3.h 608 B

12345678910111213141516171819202122232425
  1. struct List{
  2. int val;
  3. struct List * next;
  4. };
  5. void bubbleListSort(List *head) {
  6. if (head == nullptr) return; // 空链表检查
  7. List *temp2;
  8. int temp;
  9. bool swapped;
  10. do {
  11. swapped = false;
  12. temp2 = head;
  13. while (temp2->next) {
  14. if (temp2->next->val < temp2->val) {
  15. temp = temp2->val;
  16. temp2->val = temp2->next->val;
  17. temp2->next->val = temp;
  18. swapped = true;
  19. }
  20. temp2 = temp2->next;
  21. }
  22. } while (swapped); // 如果没有发生交换,提前结束
  23. }
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。