#include<iostream>
using namespace std;
int main()
{
int arr[] = { 5,4,3,2,1,7,6,9,8,10 };
int arr_len = sizeof(arr) / sizeof(arr[0]);
cout << "The length of arr is : " << arr_len<< endl;
for (int i = 0; i < arr_len-1; i++)
{
int temp = 0;
for (int j = 0; j < arr_len-1-i; j++)
{
if (arr[j + 1] < arr[j])
{
temp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = temp;
}
}
}
cout << "The arr in order are : " << endl;
for (int i = 0; i < arr_len; i++)
{
cout << "The value of arr["<<i<<"] is : " << arr[i]<<endl;
}
C++实现冒泡排序法
最新推荐文章于 2024-11-02 09:55:19 发布