/******************************
作者:cncoderalex
博客:http://blog.youkuaiyun.com/cncoderalex
*******************************/
#include <iostream>
using namespace std;
int Partion(int *pAry, int Begin, int End)
{
int T = pAry[Begin];
int i = Begin, j = End;
while (i < j)
{
while (j > i && pAry[j] > T) j--;
if (j > i)
{
pAry[i] = pAry[j];
i++;
}
while (i < j && pAry[i] < T) i++;
if (i < j)
{
pAry[j] = pAry[i];
j--;
}
}
pAry[i] = T;
return i;
}
void QuickSort(int *pAry, int Begin, int End)
{
if (NULL == pAry || Begin >= End)
return;
int Mid = Partion(pAry, Begin, End);
QuickSort(pAry, 0, Mid);
QuickSort(pAry, Mid + 1, End);
}
int main()
{
printf("http://blog.youkuaiyun.com/cncoderalex");
printf("\n");
int Ary[] = { 2, 1, 5, 8, 4, 3, 10 };
int Count = sizeof(Ary) / sizeof(int);
QuickSort(Ary, 0, Count - 1);
for (int i = 0; i < Count; i++)
{
printf("%d ", Ary[i]);
}
printf("\n");
system("pause");
return 0;
}
快速排序
最新推荐文章于 2023-12-01 23:14:38 发布