C++ Primer 学习中。。

简单记录下我的学习过程 (代码为主)

//全部容器适用



reverse(b,e)        //逆转区间数据



reverse_copy(b,e,b2)



/**------http://blog.csdn.net/u010579068------**/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
using namespace std; /*****************************************
//全部容器适用
reverse(b,e) //逆转区间数据
reverse_copy(b,e,b2)
*****************************************/
/**----------------------------------------------------------------------------------
STL算法 - 变序性算法 reverse() //逆转
reverse_copy()
rotate() //旋转
rotate_copy()
next_permutation()
prev_permutation()
random_shuffle()
partition()
stable_partition()
----------------------------------------------------------------------------------**/
/*************************************************************************************
std::reverse 全部排序容器适用 algorithm
--------------------------------------------------------------------------------------
<algorithm>template <class BidirectionalIterator>
void reverse ( BidirectionalIterator first, BidirectionalIterator last); //eg:
template <class BidirectionalIterator>
void reverse ( BidirectionalIterator first, BidirectionalIterator last)
{
while ((first!=last)&&(first!=--last))
swap (*first++,*last);
}
*************************************************************************************/ /*************************************************************************************
std::reverse_copy 全部排序容器适用 algorithm
--------------------------------------------------------------------------------------
template <class BidirectionalIterator, class OutputIterator>
OutputIterator reverse_copy ( BidirectionalIterator first,
BidirectionalIterator last, OutputIterator result );
//eg:
template <class BidirectionalIterator, class OutputIterator>
OutputIterator reverse_copy ( BidirectionalIterator first,
BidirectionalIterator last, OutputIterator result )
{
while (first!=last) *result++ = *--last;
return result;
}
*************************************************************************************/ int main()
{
vector<int> myvector;
vector<int>::iterator it; // set some values:
for (int i=1; i<10; ++i) myvector.push_back(i); // 1 2 3 4 5 6 7 8 9 reverse(myvector.begin(),myvector.end()); // 9 8 7 6 5 4 3 2 1 // print out content:
cout << "myvector contains:";
for (it=myvector.begin(); it!=myvector.end(); ++it)
cout << " " << *it;
cout << endl; int myints[] = {1,2,3}; cout << "The 3! possible permutations with 3 elements:\n"; sort (myints,myints+3);
reverse (myints,myints+3); do {
cout << myints[0] << " " << myints[1] << " " << myints[2] << endl;
} while ( prev_permutation (myints,myints+3) ); /**-------------------------------------------------------------------------------------**/
// int myints[] = {1,2,3,4,5,6,7,8,9};
deque<int> mydeque;
deque<int>::iterator iq; mydeque.resize(9); reverse_copy (myvector.begin(), myvector.end(), mydeque.begin()); // print out content:
cout << "mydeque contains:";
for (iq=mydeque.begin(); iq!=mydeque.end(); ++iq)
cout << " " << *iq;
cout << endl; return 0;
}

最新文章

  1. Vuforia图像追踪,动态创建的对象隐藏显示的坑
  2. [ActionScript 3.0] 分页排版
  3. jQuery String Functions
  4. 解决:未能加载文件或程序集“EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”
  5. 如何正确接收 GitHub 的消息邮件
  6. atitit.标准时间格式 互相转换 秒数 最佳实践
  7. 每日英语:Mistrust Between U.S., Malaysia Strains Probe
  8. ThroughRain学期冲刺总结
  9. ActiveMQ 的安装
  10. mysql与Navicat for MySQL的衔接配置问题【原创】
  11. QTcpSocket 及 TCP粘包分析
  12. 关于EF+MVC5分页查询数据效率问题
  13. [Codeforces 696D] Legen...
  14. Linux的文件类型
  15. nginx配置默认首页(index.htnl index.htm)全流程(包含遇到问题的解决)
  16. windows10 php7安装mongodb 扩展及其他扩展的思路
  17. 快速学习MarkDown语法及MarkDown拓展语法
  18. python系统编程(十二)
  19. 将 ASP.NET Core 2.0 项目升级至 ASP.NET Core 2.1 RC 1
  20. mail 发送email

热门文章

  1. Jquery EasyUI环境下设置下拉框选中指定选项
  2. 《Java编程的逻辑》第一部分 编程基础与二进制
  3. PHP基础知识测试题及解析
  4. CSS——规避脱标流和vertical-align
  5. javascript的严格模式:use strict
  6. C#斐波那契数列方法
  7. PHP操作Redis相关函数
  8. 【解题报告】 洛谷 P3492 [POI2009]TAB-Arrays
  9. POJ1161——The Suspects
  10. Linux下的find命令