#include
void swap(int *p1, int *p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
void select_sort(int *start, int n, int increase)
{
int *p1, *p2, *p3;
if(increase)
{
for(p1=start; p1 {
p3=p1;
for(p2=p1+1; p2 {
if(*p2<*p3)
p3=p2;
}
swap(p1,p3);
}
}
else
{
for(p1=start; p1 {
p3=p1;
for(p2=p1+1; p2 {
if(*p2>*p3)
p3=p2;
}
swap(p1,p3);
}
}
}
void printarray(int *a,int n)
{
int i;
for(i=0; i printf("%3d",*(a+i));
printf("\n");
}
int main(void)
{
int a[10]={1,5,2,3,0,7,4,9,6,8};
select_sort(a,10,1);
printarray(a,10);
return 0;
}
阅读(586) | 评论(0) | 转发(0) |