快速排序
#include<bits/stdc++.h> using namespace std; int a[5] = { 5,1,2,4,3 }; int partition(int begin, int end) { int pivot = begin - 1; for (int i = begin; i <= end - 1; i++) if (a[i] < a[end]) swap(a[i], a[++pivot]); swap(a[++ pivot], a[end]); return pivot; } void quicksort(int begin, int end) { if (begin < end) { int pivot = partition(begin, end); quicksort(begin, pivot - 1); quicksort(pivot + 1, end); } } int main() { quicksort(0, 4); for (int i = 0; i < 5; i++)cout << a[i] << " "; return 0; }
标签:std,begin,专题,end,int,排序 From: https://www.cnblogs.com/-ark/p/16885508.html