#include "stdafx.h"
#include <iostream>
using namespace std;
// divide the origin number series into two part
int partition(int arr[], int low, int high)
{
int i = low;
int j = high;
int pivot = arr[i];
while(i < j)
{
while(i<j && arr[j]>=pivot) j--;
if(i<j) arr[i++] = arr[j];
while(i<j && arr[i]<=pivot) i++;
if(i<j) arr[j--] = arr[i];
}
arr[i] = pivot;
return i;
}
void quick_sort(int arr[], int low, int high)
{
if(low >= high) return;
int pivot_pos = partition(arr, low, high);
quick_sort(arr, low, pivot_pos-1);
quick_sort(arr, pivot_pos+1, high);
}
// start from here
int main()
{
int arr[10];
int arr2[10];
cout << "输?出?10个?数簓据Y:阰";
for(int i=0; i<10; i++)
{
cin >> arr[i];
arr2[i] = arr[i];
}
quick_sort(arr2, 0, 9);
cout << "排?序ò后ó:阰" <<endl;
for(int i=0; i<10; i++) cout << arr2[i] << " ";
cout << endl;
system("PAUSE");
return 0;
}
评论0
最新资源