<span style="font-family:Microsoft YaHei;font-size:14px;">int partion(int arr[], int left, int right)
{
if (left < right)
{
int key = arr[right];
int prev = left - 1;
int cur = left;
while (cur < right)
{
while (arr[cur] < key && ++prev != cur)
{
std::swap(arr[cur], arr[prev]);
}
++cur;
}
std::swap(arr[++prev], arr[right]);
return prev;
}
return -1;
}
// [left ,right]
void QuickSort(int arr[], int left, int right)
{
assert(arr);
if (left < right)
{
std::stack<int> s;
s.push(left);
s.push(right);
while (!s.empty())
{
int end = s.top();
s.pop();
int begin = s.top();
s.pop();
int pos = partion(arr, begin, end);
if (pos - 1 > begin)
{
s.push(begin);
s.push(pos - 1);
}
if (pos + 1 < end)
{
s.push(pos+1);
s.push(end);
}
}
}
}</span>
这就是源码 , 具体的分析过程:http://blog.csdn.net/my_heart_/article/details/52383165