2015-10-21 06:30:01
阅读( 84 )
#include “stdafx.h”
#define N 10
int part(int list[], int low, int high) { // 一趟排序,返回分割点位置
int tmp = list[low];
while(low
while(low=tmp) –high;
list[low] = list[high];
while(low
list[high] = list[low];
}
list[low] = tmp;
return low;
}
void QSort(int list[], int low, int high) { // 应用递归进行快速排序
if(low
int mid = part(list, low, high);
QSort(list, low, mid-1);
QSort(list, mid+1, high);
}
}
void show(int list[], int n) { // 输出列表中元素
for(int i=0; i
printf(“%d “, list[i]);
printf(“\n”);
}
int main(int argc, char* argv[]) {
int list[N] = {23, 65, 26, 1, 6, 89, 3, 12, 33, 8};
show(list, N); // 输出排序前序列
QSort(list, 0, N-1); // 快速排序
show(list, N); // 输出排序后序列
}
分享给朋友:
亲~ 如果您有更好的答案 可在评论区发表您独到的见解。
您想查看更多的信息:
面试题