#include <stdio.h>
void sort(int *a,int n);
#define MAXN 50
int array[MAXN];
int main(void)
{
int i=0;
int j=0;
int input;
while(scanf("%d",&input)==1){
array[i++]=input;
}
sort(array,i);
while(i--){
printf("%d ",array[j]);
++j;
}
return 0;
}
void sort(int *a,int n)
{
int count=1;
int i;
int c=0;
int *temp;
temp=&c;
while(n>1){
while(count<n){
a++;
if(*(a-1)>*a){
*temp=*(a-1);
*(a-1)=*a;
*a=*temp;
}
++count;
}
printf("\n");
--n;
a-=n;//注意此时a不要加1因为这时的n已经减了1
count=1;
}
}
sort冒泡指针的排序
最新推荐文章于 2024-05-25 18:21:00 发布