You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
//冒泡排序
|
|
|
|
|
#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*/
|