快速排序
来源:互联网 发布:淘宝购物优惠微信群 编辑:程序博客网 时间:2024/05/22 18:09
public class QuickSort {public static void main(String args[]){int a[] = {10,5,10,2};System.out.println("this is quciksort:");QuickSort(a, 0, a.length - 1);output(a);}public static void output(int a[])//输出{int i;for(i = 0; i < a.length; i++){System.out.print(a[i] + " ");}System.out.println();}public static void QuickSort(int a[], int low, int high){if(low >= high){return;}int l = low;int h = high;int now = a[low];//设置哨兵while(l < h){while(l < h && a[h] >= now)//右比较{h--;}while(l < h && a[l] <= now)//左比较{l++;}if(l < h)//交换{int temp = a[h];a[h] = a[l];a[l] = temp;} }int temp = a[l];//换最后的一个值a[l] = now;a[low] = temp;QuickSort(a, low, l - 1);//左递归QuickSort(a, h + 1, high);//右}}
阅读全文
0 0
- 快速排序
- 快速排序
- 快速排序
- 快速排序!
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- 快速排序
- JDBC保存、读取大文本数据类型
- NYOJ 45 棋盘覆盖 (大数问题)
- 二进制位运算应用
- 爬动的蠕虫
- Android进阶二:序列化总结(基础篇)
- 快速排序
- push 0x******* retn 的应用
- oracle数据增删改
- 深入理解PHP:高级技巧、面向对象与核心技术(原书第3版) -- 设计模式之组合模式
- LeetCode 90. Subsets II
- hdu6213 Chinese Zodiac
- c++基础之读取数据
- 输入、输出阻抗以及阻抗匹配
- px, dp, dip, sp之间的区别