#include <stdio.h>
#include <stdlib.h>
int nums[
5];
int main()
{
int i,j;
for(i=
0;i<
5;i++){
scanf(
"%d",&nums[i]);
}
sort(
0,
4);
printf(
"\n");
for(i=
0;i<
5;i++){
printf(
"%d ",nums[i]);
}
return 0;
}
void sort(
int low,
int hight){
if(low >= hight)
return;
int target = nums[low];
int i = low,j = hight;
while(low < hight){
while(target < nums[hight]){
hight --;
}
if(low < hight)
nums[low++] = nums[hight];
while(target > nums[low]) {
low ++;
}
if(low < hight)
nums[hight--] = nums[low];
}
nums[low] = target;
sort(i,low-
1);
sort(low+
1,j);
}
(低位高位指左右两边的游标) 方法总结:头为基准,高位从右找小数,找到将左低位数变为找到的高位小数,再从低位左边找大数,找到将右边高位数变为找到的低位大数,当两游标相遇时将低位数变为基准数,结束一次比较,再以低位数为中心分为左右两边,继续使用递归排序。