快速排序
2015-09-02 18:22
246 查看
package q; public class QuickSort<E extends Comparable> { public static void quickSort(Integer [] list){ quickSort(list,0,list.length-1); } private static void quickSort(Integer[] list,Integer first,Integer last){ if(last > first){ Integer pivotIndex = partition(list,first,last); quickSort(list,first,pivotIndex - 1); quickSort(list,pivotIndex + 1,last); } } private static Integer partition(Integer[] list,Integer first,Integer last){ Integer pivot = list[first]; Integer low = first +1; Integer high = last; while(high > low){ while (low <= high && list[low] <= pivot) low++; while (low <= high && list[high] >= pivot) high--; if(high > low){ int temp = list[high]; list[high] = list[low]; list[low] = temp; } } while(high > first && list[high] >= pivot) high--; if(pivot > list[high]){ list[first] = list[high]; list[high] = pivot; return high; } else{ return first; } } }
相关文章推荐
- Linux权限管理之ACL权限
- STM32F4使用硬件SPI驱动ADS8322
- Java基础-----基础小结
- 【转】 定义模板和服务
- 协变(Covariance)与逆变(Contravariance)
- 操作系统重装后一系列软件重装
- 快速求幂二分算法
- Android Location服务之Geocoder
- eval解析
- centos创建ftp方法,个人经验
- 收藏基本Java项目开发的书
- 基于HFSS的天线设计流程
- 接口的使用
- Maven assembly打包文件被覆盖问题
- 《git权威指南》第4章git初始化--读书笔记
- HDU 5159 Card(数学期望)
- 代理模式之JDK动态代理
- java 获取时间
- 在HTML中打出人民币符号和对勾符号
- Linux主要shell命令详解