标签:std oid for 验证 常见 sort \n while array
快速排序:
#include<stdio.h>
int Array_Sort[] = {3,1,2,0,4,6,5,9,7,8};
int FindPos(int *Array,int low,int high)
{
int val = Array[low];
while(low<high)
{
while(low<high && val <= Array[high]) 此处必须先从high开始
{
--high;
}
Array[low] = Array[high];
while(low<high && val >= Array[low])
{
++low;
}
Array[high] = Array[low];
}
Array[low] = val;
return low;
}
void Quick_Sort(int *Array,int low,int high)
{
int pos;
if(low<high)
{
pos = FindPos(Array,low,high);
Quick_Sort(Array,low,pos-1);
Quick_Sort(Array,pos+1,high);
}
}
int main(void)
{
int i = 0;
Quick_Sort(Array_Sort,0,9);
for(i = 0; i < 10 ; i++)
{
printf("%d\r\n",Array_Sort[i]);
}
return 0;
}
注:以上所有程序都经过作者多次验证,如有错误,请多指正。
标签:std oid for 验证 常见 sort \n while array
原文地址:https://www.cnblogs.com/muzixiaofeng/p/10088602.html