#include<stdio.h>
#include<iostream>
using namespace std;
int m_partition(int a[], int low, int high)
{
int temp = a[low];
while (low < high)
{
while (low < high && a[high] >= temp)
high--;
a[low] = a[high];
while (low < high && a[low] <= temp)
low++;
a[high] = a[low];
}
a[low] = temp;
return low;
}
void quickSort(int a[], int low, int high)
{
if(low < high)
{
int pivot = m_partition(a, low, high);
quickSort(a, low, pivot);
quickSort(a, pivot+1, high);
}
}
int main(int argc, char * argv[])
{
int a[] = {-4, 3, 56, -15, 34, 0, -14, 4};
int n = sizeof(a)/sizeof(int);
quickSort(a, 0, n-1);
for (int i = 0; i < n; i++)
cout<<a[i]<<" ";
return 1;
}
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布