#include<iostream>
using namespace std;
void Swap_Elem(int *arr, int first, int second)
{
int temp = arr[first];
arr[first] = arr[second];
arr[first] = temp;
}
int Patition(int *arr, int low, int high)
{
int mid = high / 2;
if (arr[low] > arr[high])
{
Swap_Elem(arr, low, high);
}
if (arr[mid] > arr[high])
{
Swap_Elem(arr, mid, high);
}
if (arr[mid] > arr[low])
{
Swap_Elem(arr, mid, low);
}
int pivot = arr[low];
while (low < high)
{
while (low < high && arr[high] >= pivot)
{
high--;
}
arr[low] = arr[high];
while (low < high && arr[low] <= pivot)
{
low++;
}
arr[high] = arr[low];
}
arr[low] = pivot;
return low;
}
void Quick_Sort(int *arr, int low, int high)
{
int pivot;
while (low < high)
{
pivot = Patition(arr, low, high);
Quick_Sort(arr, low, pivot - 1);
low = pivot + 1;
}
}
int main()
{
int *arr = new int[10];
for (int i = 0, num = 11; i < 10; i++, num--)
{
arr[i] = num;
}
cout << "排序前:" << endl;
for (int i = 0; i < 10; i++)
{
cout << arr[i] << "\t";
}
cout << endl;
Quick_Sort(arr, 0, 9);
cout << "排序后:" << endl;
for (int i = 0; i < 10; i++)
{
cout << arr[i] << "\t";
}
system("pause");
return 0;
}