#include "stdafx.h"
void fastRank(int arr[],int left,int right)
{
int i = left;
int j = right;
int key = arr[i];
if (left < right)
{
while(i < j)
{
while (arr[j] > key && i < j)
{
j--;
}
arr[i] = arr[j];
while (arr[i] < key && i < j)
{
i++;
}
arr[j] = arr[i];
}
arr[i] = key;
fastRank(arr,left,i-1);
fastRank(arr,j+1,right);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
const int nSize = 9;//数组大小;
int arr[nSize] = {66,21,47,58,83,10,24,5,96}; //定义数组;
fastRank(arr, 0, nSize - 1);
//打印;
for (int i = 0; i < nSize; i++)
{
printf("%d ",arr[i]);
}
while (1)
{
}
return 0;
}
快速排序
最新推荐文章于 2021-12-16 18:46:43 发布