This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
//冒泡排序
#include<stdio.h>
void bubbleSort(int a[],int n)
{
int temp;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
int main()
{
int a[1000];
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
bubbleSort(a,n);
for(int i=0;i<n;i++)
printf("%d ",a[i]);
return 0;
}
/*冒泡排序:时间复杂度平均情况为O(n^2)。
运行稳定。
一般在学习排序原理的时候说明使用,在实际应用中不会使用。
Process exited after 12.6 seconds with return value 0*/