#include<stdio.h>
//冒泡排序
void BubbleSort(int a[],int n)
{
int temp,i,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]<a[j])
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
int main()
{
int a[] = {1,2,3,4,5,6};
int n = 6;
BubbleSort(a,n);
int i = 0;
for(i=0;i<n;i++){
printf("%d ",a[i]);
}
return 0;
}
有问题,欢迎评论区一起讨论
本人Hexo博客地址:https://qietingfengyindiary.github.io/