冒泡排序法:
#include <stdio.h>
#define N 5
int a[N];
void show_data()
{
int i;
for(i=0; i<N; i++){
printf("%d\t",a[i]);
}
puts("");
}
void bubble_sort()
{
int i,j,temp;
for(i=0; i<N-1; i++){
for(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 argc, const char *argv[])
{
int i;
printf("please input 5 number > ");
for(i=0; i<N; i++){
scanf("%d",&a[i]);
}
show_data();
bubble_sort();
show_data();
return 0;
}