c++冒泡排序
#include <iostream>
int main() {
int arr[]={4,8,2,3,1,0,9,7,6};
std::cout<<"排序前的数组:"<<arr<<std::endl;
int arr_length = sizeof(arr)/ sizeof(arr[0]);
std::cout<<"数组的元素个数:"<<arr_length<<std::endl;
for (int i=0;i<arr_length-1;i++){
for(int j=0;j<arr_length-i-1;j++){
if(arr[j]>arr[j+1]){
int temp = arr[j];
arr[j] =arr[j+1];
arr[j+1] = temp;
}
}
}
for (int i = 0; i < arr_length; i++)
{
std::cout << arr[i] << std::endl;
}
return 0;
}