#include<iostream>
using namespace std;
void swap(int &a,int &b)
{
int temp = a;
a = b;
b = temp;
}
void bubblesort(int A[],int n){
int i, j;
for ( i = 0; i < n-1; i++){
for( j = n-1; j>0; j--){
if(A[j-1]>A[j])
{
swap(A[j-1],A[j]);
}
}
}
for(int k = 0; k < n;k++){
cout<<A[k]<<endl;
}
}
int main(){
int A[9]={2,3,1,4,5,3,7,8,0};
bubblesort(A,9);
return 0;
}
bubblesort.cpp
最新推荐文章于 2021-10-25 20:59:03 发布