我正在浏览快速排序和我看到的任何文章,我越来越困惑。快速排序混淆
1)本实施好才是真的好http://gauss.ececs.uc.edu/Courses/C321/html/quicksort.java.html
但据我了解,每遍之后,枢轴指数在正确的位置。
那么理想,我们应该做以下几点:
public static void Quicksort(int A[], int f, int l)
{
if (f >= l) return;
int pivot_index = partition(A, f, l);
Quicksort(A, f, pivot_index-1); //*** pivot_index-1
Quicksort(A, pivot_index+1, l);
}
但教程使用快速排序(A,F,pivot_index);。
我200%肯定,使'pivot_index-1'的变化不会提高任何性能或降低复杂性;但只是如果我的理解是正确的就想做出来。
2)执行here有效;但并不是每次传递都会将主元素放置在正确的位置。
看看这里http://xoax.net/comp_sci/crs/algorithms/lessons/Lesson4/ – Arpit 2013-02-20 17:00:50