您的位置:首页 > 其它

算法入门(一) 排序

2016-03-23 21:15 387 查看
摘自 <Algorithms_4th> Robert Sedgewick, chapter 2 sorting

the following class illustrates the conventions that we will use

public class Quick
{
public static void sort(Comparable[] a)
{
StdRandom.shuffle(a); // Eliminate dependence on input.
sort(a, 0, a.length - 1);
}
private static void sort(Comparable[] a, int lo, int hi)
{
if (hi <= lo) return;
int j = partition(a, lo, hi); // Partition (see page 291).
sort(a, lo, j-1);     // Sort left part a[lo .. j-1].
sort(a, j+1, hi);     // Sort right part a[j+1 .. hi].
}
}


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: