#include <iostream>
#include <vector>
void show(std::vector<int>& vec)
{
for (int i = 0; i < vec.size(); i++)
std::cout << vec[i] << " ";
std::cout << std::endl;
}
int main()
{
int a[] = { 5, 8, 4, 3, 1, 9, 0, 10 };
std::vector<int> vec(a, a + 8);
int length = vec.size();
bool flag = true;
for (int i = 0; i <= length - 2 && flag; i++)
{
flag = false;
for (int j = length - 2; j >= i; j--)
{
if (vec[j] > vec[j + 1])
{
std::swap(vec[j], vec[j + 1]);
flag = true;
}
}
}
show(vec);
return 0;
}
}
2021-05-04
最新推荐文章于 2021-05-13 11:35:48 发布