#include <iostream>
using namespace std;
int main()
{
// 利用冒泡排序实现升序序列
int arr[9] = {
4, 2, 8, 0, 5, 7, 1, 3, 9};
cout << "排序前: " << endl;
for (int i = 0; i < 9; i++)
{
cout << arr[i] << " ";
}
cout << endl;
// 开始冒泡排序
for (int i = 0; i < 9; i++)
{
for (int j = i + 1; j < 9; j++)
{
if (arr[i] > arr[j])
{
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
}
cout << "排序后: " << endl;
for (int i = 0; i < 9; i++)
{
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
[c++] - 简单的冒泡
猜你喜欢
转载自blog.csdn.net/piano9425/article/details/111714047
今日推荐
周排行