冒泡和快速排序
发布日期:2021-11-07 06:40:19 浏览次数:3 分类:技术文章

本文共 1899 字,大约阅读时间需要 6 分钟。

也没专门去研究过排序。只是平常用过这两种和这两种的变形:冒泡和快速。收录一下用的时候直接Copy就OK。

public class Method    {       public static void QuickSort(List
arrays, int low, int high) { int i = low; int j = high; if (low < high) { int key = arrays[low]; while (i < j) { while (i < j && arrays[j] > key) { j--; } if (i < j) { arrays[i] = arrays[j]; i++; } while (i < j && arrays[i] < key) { i++; } if (i < j) { arrays[j] = arrays[i]; j--; } } arrays[i] = key; QuickSort(arrays, low, i - 1); QuickSort(arrays, i + 1, high); } } public static void Bubble(List
sortList) { if (sortList == null || sortList.Count <= 0) { return; } int flag = 1; int i, j; int itemCount = sortList.Count; int itemTemp; for (i = 1; i < itemCount && flag == 1; i++) { flag = 0; for (j = 0; j < itemCount - i; j++) { int countfore = sortList[j]; int countback = sortList[j + 1]; if (countfore > countback) { flag = 1; itemTemp = sortList[j]; sortList[j] = sortList[j + 1]; sortList[j + 1] = itemTemp; } } } } }

转载地址:https://blog.csdn.net/yysyangyangyangshan/article/details/7392360 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:读书笔记22:职责链模式
下一篇:用心做软件—细节决定成败

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月09日 02时03分23秒