原创

C++快速排序代码

浏览:174
更新时间:2022-04-24
发布于:未知
微信扫一扫
分享至其他
0
表情
漩涡
0/200
全部评论
麻雀𝓜𝓾𝓪𝓒𝓱𝓾𝓮
山不在高,有仙则名。水不在深,有龙则灵
作品说明
#include<iostream> #include<ctime> #include<cstdlib> using namespace std; Paritition(int A[], int low, int high) { int pivot = A[low]; while (low < high) { while (low < high && A[high] >= pivot) { --high; } A[low] = A[high]; while (low < high && A[low] <= pivot) { ++low; } A[high] = A[low]; } A[low] = pivot; return low; } void QuickSort(int A[], int low, int high) {
操作说明
if (low < high) { int pivot = Paritition(A, low, high); QuickSort(A, low, pivot - 1); QuickSort(A, pivot + 1, high); } } int main() { int i,k,b[100000]; srand(time(NULL)); for( i=0; i<100000;i++ ) { b[i]=rand()%100000+1; } QuickSort(b,0,i-1); for(int i = 0;i<100000;i++) { cout<<b[i]<<" "; } }