STL中vector容器实现反转(reverse)
2024-09-28 13:35:18
vector容器中实现可以通过以下两种方式实现:
#include "stdafx.h"
#include <vector>
#include <iostream>
//#include <math.h> #include <algorithm> using namespace std; int _tmain(int argc, _TCHAR* argv[])
{ vector<int> arrayInt;
arrayInt.resize();
for (int i=;i<;i++)
{
arrayInt[i]=i;
} vector<int> arrayRever;
arrayRever.reserve(arrayInt.size()); //vector反转 //------------------------------------------------------------------------------
//>>>
//方法一:使用vector自带的反转迭代器reverse_iterator,rbegin(),rend()
vector<int>::reverse_iterator riter;
for (riter=arrayInt.rbegin();riter!=arrayInt.rend();riter++)
{
arrayRever.push_back(*riter);
}
//<<<
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
//>>>
//方法二:使用<algorthm>中的reverse()
//arrayRever=arrayInt;
//reverse(arrayRever.begin(),arrayRever.end());
//<<<
//------------------------------------------------------------------------------ //
for (int i=;i<arrayRever.size();i++)
{
cout<<"arrayRever["<<i<<"]"<<" "<<arrayRever[i]<<endl;
} return ;
}
最新文章
- 17、ASP.NET MVC入门到精通——Spring.net入门
- Bullet物理引擎在OpenGL中的应用
- 【iCore3双核心板】iCore3双核心板使用说明(图文)
- 浅谈PHP与手机APP开发(API接口开发)
- 基于Html5的兼容所有主流浏览器的在线视频播放器videoJs
- linux网络配置相关文件
- 第27本:《学得少却考得好Learn More Study Less》
- ava集合---LinkedList源码解析
- Delegate &; Event
- CC2640蓝牙芯片开发备记
- no plugin found for prefix &#39;tomcat 7&#39; in the current project and in the plugin groups的解决方法
- Js中instanceof 的用法
- Loadrunner和JMeter并发对比
- Python Redis list
- unigui结合JS方法记录
- [Java程序员面试宝典]读书笔记
- leetcode 算法 Excel表列序号 python实现
- vi命令速查图
- Kotlin中的object 与companion object的区别
- linux 的 磁盘管理
热门文章
- Linux多线程下载工具Axel
- Can&#39;t locate ExtUtils/MakeMaker.pm
- Spring中@Resource与@Autoware
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.5. 配置网络
- ArcGlobe点击IGlobeServerLayer图层读取信息
- 分享一些Comet开发经验
- OFBIZ安装
- Basic Sorting Algorithms
- Application Cache
- asp.net mvc让我告诉你请求从哪里来