// Author: FF-w
// Date: 24, Sep, 2018
// Purpose: Bubble Sort
#include<iostream>
using namespace std;
void bubble_sort(int array[],int arrayLength)
{
int i,j,temp;
for(i=0;i<arrayLength-1;i++){
for(j=0;j<arrayLength-1-i;j++){
if(array[j]>array[j+1]){
temp=array[j+1];
array[j+1]=array[j];
array[j]=temp;
}
}
}
}
void print_array(int array[],int arrayLength)
{
for(int n=0;n<arrayLength;n++){
cout<<array[n]<<" ";
}
}
int main(){
int arr[]={34,89,23,45,5,23,4,78,26,67};
bubble_sort(arr,10);
print_array(arr,10);
return 0;
}
冒泡排序
最新推荐文章于 2021-06-24 11:47:51 发布