1 #include "iostream"
2 using namespace std;
3
4 //************冒泡排序法*********
5 int bubble_sort(int n,int array[100]){
6 bool exchange;
7 int i,j,temp;
8 i=1;
9 do{
10 exchange=false;
11 for(j=n-1;j>=i;j--){
12 if(array[j]<array[j-1]){
13 temp=array[j-1];
14 array[j-1]=array[j];
15 array[j]=temp;
16 exchange=true;
17 }
18 }
19 i++;
20 }while((i<=n-1)&&(exchange=true));
21 return 0;
22 }
23 //************冒泡排序法*********
24
25 int print(int n,int array[100]){
26 int i;
27 for(i=0;i<n;i++){
28 cout<<array[i]<<" ";
29 }
30 cout<<endl;
31 return 0;
32 }
33
34 int main()
35 {
36 int array[10]={1,4,5,6,7,23,41,34,7,8};
37 bubble_sort(10,array);
38 print(10,array);
39 return 0;
40 }