void swap(int list[], int first, int second) {
int temp = list[first];
list[first] = list[second];
list[second] = temp;
}
int partition(int list[], int first, int last) {
int pivot;
int index, smallIndex;
swap(list, first, (first+last)/2);
pivot = list[first];
smallIndex = first;
for(index=first+1; index<=last; index++)
if(list[index]<pivot) {
smallIndex++;
swap(list, smallIndex, index);
}
swap(list, first, smallIndex);
return smallIndex;
}
void recQuickSort(int list[] , int first, int last) {
int pivotLocation;
if(first<last) {
pivotLocation = partition(list, first, last);
recQuickSort(list, first, pivotLocation-1);
recQuickSort(list, pivotLocation+1, last);
}
}
分享到:
相关推荐
快速排序 c++ 源代码, 算法,排序问题快速排序 c++ 源代码, 算法,排序问题
数据结构--快速排序C++源代码,自己编写调试,代码简单易懂,不长
数据结构のC++快速排序。VC6.0调试通过。
快速排序c,快速排序c++源码,和详细教程
《数据结构课设》快速排序C++实现 内含流程图、源代码、完整设计报告……
这是在WINDOWS下实现的多进程多线程的快速排序程序,其中为了加快排序速度使用了文件映射技术。
快速排序(quick sort)C++源代码
严奶奶《数据结构》书上快速排序的C++算法实现,随机生成10个100以内的数,然后快速排序,并输出比较次数
环境 Microsoft Visual C++ 6.0 快速排序 控制台程序 内含实验报告
快速排序的c++代码 请大家免费使用 还有堆排序呢 O ∩ ∩ O
用c++写的快速排序 Swap交换两个int类型的数据 Sort排序 QuickSort快速排序(递归) main
快速排序 C,时间复杂度nlogn 快速排序问题.cpp
算法导论排序算法C++实现。被算法导论优美的叙述折服,用C++实现一下加深理解
快速排序、归并排序、改进的归并排序算法的C++代码。(含测试用例,代码逻辑清晰可运行。) (划分子区间,分别对左右子区间进行排序,开始归并已经排好序的low到high之间的数据。改进后的归并排序对数组元素下标...
本代码是快速排序的c++源代码,充分体现了快速排序算法的特点,思路清晰,适合仔细研读
快速排序法 C++ 初学者代码 简单的准确的