#include <stdio.h>
int main( )
{
void sort(int a[],int n);
int i,arr[]={12,60,21,45,13,55,19,28,71,32};
sort(arr,10);
for(i=0;i<10;i++)
printf("%4d",arr[i]);
printf("\n");
return 0;
}
void sort(int a[],int n )
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++ )
if(a[j]>a[j+1])
temp=a[j],a[j]=a[j+1],a[j+1]=temp;
}
}
采用冒泡法对一维数组中的数据按升序进行排序。
最新推荐文章于 2024-02-08 18:15:48 发布