C++使用STL对随机生成的向量各元素进行排序
#include
#include
#include
#include
#includeusing namespace std;
void Display(vector&V);
int main(void)
{
srand(time(NULL));
vector V(10);
for (int i = 0;
i < 10;
i++)
{
V[i] = rand() % 100;
//随机生成向量的每个分量
}
cout << "排序前:" << endl;
Display(V);
sort(V.begin(), V.end());
//调用sort算法排序
cout << "排序後:" << endl;
Display(V);
system("pause");
return 0;
}void Display(vector&V)
{
vector::const_iterator iter;
for (iter = V.begin();
iter != V.end();
iter++)
{
cout << *iter << " ";
}
cout << endl;
}
![C++使用STL对随机生成的向量各元素进行排序](https://img.it610.com/image/info10/cde15979c4f246578cd6a19ee5c7a49e.png)
文章图片
输出.PNG 本程序在visual studio 2017 下编译运行成功
推荐阅读
- 由浅入深理解AOP
- 【译】20个更有效地使用谷歌搜索的技巧
- mybatisplus如何在xml的连表查询中使用queryWrapper
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- MybatisPlus使用queryWrapper如何实现复杂查询
- opencv|opencv C++模板匹配的简单实现
- iOS中的Block
- Linux下面如何查看tomcat已经使用多少线程
- 使用composer自动加载类文件
- android|android studio中ndk的使用