#include<stdio.h> #include<stdlib.h> void bubbleSort(int * data,int n) { int i,j,k; for(i=0;i < n-1;i++) //n datas only need n-1 times sort; { for(j = 0; j < n-i-1;j++) //compare times of each sort is n-i-1; { if(data[j]>data[j+1]) { k = data[j]; data[j] = data[j+1]; data[j+1] = k; } } } } void main() { int i; int data[7] = {4,5,3,87,1,99,33}; for( i = 0;i < 7;i++) { printf("%-3d",data[i]); } bubbleSort(data,7); printf("\nAfter sorted:\n"); for( i = 0;i < 7;i++) { printf("%-3d",data[i]); } printf("\n"); system("pause"); }