这是个什么鬼__2018.08.16
程序员文章站
2024-03-17 19:34:16
...
代码:
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <time.h>
using namespace std;
void Print(vector<int>MyVector)
{
vector<int>::iterator it = MyVector.begin();
for (;it != MyVector.end();++it)
{
cout << *it << " ";
}
cout << endl;
}
void Sort(vector<int> MyVector)
{
vector<int>::iterator it = MyVector.begin();
for (int i = 0;i < MyVector.size();++i)
{
it = MyVector.begin();
for (int j = 0;j < MyVector.size()-1;++j,++it)
{
if (*it > *(it + 1))
{
int temp = *it;
*it = *(it + 1);
*(it + 1) = temp;
}
}
}
Print(MyVector);
}
int main()
{
vector<int> MyVector;
srand(time(NULL));
for (int i = 0;i < 10;++i)
{
MyVector.push_back(rand() % 100);
}
cout << "MyVector.size()=" << MyVector.size() << endl;
Print(MyVector);
Sort(MyVector);
Print(MyVector);
return 0;
}
上一篇: 题库(16)_数组中二分查找
下一篇: 亲缘性线程池,这是什么鬼?