ckook

导航

 

2012年10月24日

摘要: 快速排序算法里的partition函数用来解决这样一个问题:给定一个数组arr[]和数组中任意一个元素a,重排数组使得a左边都小于它,右边都不小于它。 // arr[]为数组,start、end分别为数组第一个元素和最后一个元素的索引 // povitIndex为数组中任意选中的数的索引 1 int partition(int arr[], int start, int end, int pivotIndex) 2 { 3 int pivot = arr[pivotIndex]; 4 swap(arr[pivotIndex], arr[end]); 5 int stor... 阅读全文
posted @ 2012-10-24 22:35 ckook 阅读(17214) 评论(2) 推荐(1)