java实现快速排序的方法
java实现快速排序的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:本文实例讲述了java实现快速排序的方法。分享给大家供大家参考。具体实现方法如下:publicclassQuick{publicstatic...

本文实例讲述了java实现快速排序的方法。分享给大家供大家参考。具体实现方法如下:

public class Quick { public static int[] Data = { 9, 8, 7, 4, 1, 12, 15, 63, 15, 20 }; public static void quick(int left, int right) { int i, j; int Pivot; int temp; i = left; j = right; Pivot = Data[(left+right)/2]; while (i < j) { while (Data[i] < Pivot)i++; while (Data[j] > Pivot) j--; if (i <= j) { temp = Data[i]; Data[i] = Data[j]; Data[j] = temp; i++; j--; } } if (left < j) quick(left, j); if (i < right) quick(i, right); } public static void main(String[] args) { System.out.println("aaa"); quick(0, 9); System.out.println("bbb"); for (int a = 0; a < Data.length; a++) { System.out.print(Data[a] + " "); } } }

希望本文所述对大家的java程序设计有所帮助。

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Java学习
热门Java学习
编程开发子分类