欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

这是个什么鬼__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;
}

这是个什么鬼__2018.08.16