双指针法
//升序排列
void quick_sort(int* A, int start, int end) {
if (start >= end) return;
int i = start, j = end, key = A[start];
while (i < j) {
while (i < j && !(A[j] < key)) j--;
A[i] = A[j];
while (i < j && A[i] < key) i++;
A[j] = A[i];
}
A[i] = key;
quick_sort(A, start, i - 1);
quick_sort(A, i + 1, end);
}
##非递归
void QuickSortNor(vector<int> &v, int left, int right)
{
if (left >= right)
return;
stack<int> s;
s.push(left);
s.push(right);
while (!s.empty())
{
int right = s.top();
s.pop();
int left = s.top();
s.pop();
if (left < right)
{
int boundary = partition1(v, left, right);
// 左区间
s.push(left);
s.push(boundary);
// 右区间
s.push(boundary + 1);
s.push(right);
}
}
}