求快速排序算法的代码

来源:百度知道 编辑:UC知道 时间:2024/06/16 23:57:43
快速排序算法的代码 要完整的 长一点的大约100行左右就行 放在Visual Studio6.0程序能运行 我试了能运行马上给分!!

BOOL QuickSort(U16*p,int num)
{
int i;
int n_small=1,n_big=num-1;//升序
U16 m_key=p[0];
BOOL xiaokong=true;//小头有空
int m_free = 0;

if(num<=1)return true;///递归终止条件
for(i=0;i<num-1;i++)
{
if(xiaokong)//小头有空
{
if(p[n_big]<m_key)
{
p[m_free]=p[n_big];
m_free=n_big;
xiaokong=false;
}
n_big--;
}
else//大头有空
{
if(p[n_small]>m_key)
{
p[m_free]=p[n_small];
m_free=n_small;
xiaokong=true;
}
n_small++;
}
}
if(m_free != 0)
{
p[m_free]=m_key;
}
//printf("num=%d[", num);
//for( i = 0; i< num; i++) printf("%d,", p[i]);
//printf("]key=%d, mid = %d, small=%d, big=%d, from %d num %d && from %d num %d\n",
// m_key, m_free, n_small, n_big, 0,m_free,