zoukankan      html  css  js  c++  java
  • C++ STL 逆转旋转 reverse reverse_copy rotate

    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <iterator>

    using namespace std;

    int main()
    {
      vector<int> vec1;
      for (int k=0;k<10;k++)
      {
        vec1.push_back(k);
      }

      vector<int>::iterator vec_iter1;
      for (vec_iter1 = vec1.begin();vec_iter1 != vec1.end();++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "---------------------------------------" << endl;

      //逆转
      reverse(vec1.begin(), vec1.end());

      for (vec_iter1 = vec1.begin(); vec_iter1 != vec1.end(); ++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "---------------------------------------" << endl;

      vector<int> vec2;
      reverse_copy(vec1.begin(), vec1.end(), ostream_iterator<int>(cout," "));
      cout << endl;
      cout << "---------------------------------------" << endl;

      //旋转
      rotate(vec1.begin(), vec1.begin() + 5, vec1.end());

      for (vec_iter1 = vec1.begin(); vec_iter1 != vec1.end(); ++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "---------------------------------------" << endl;

      rotate(vec1.begin(), find(vec1.begin(), vec1.end(), 9), vec1.end());

      for (vec_iter1 = vec1.begin(); vec_iter1 != vec1.end(); ++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "---------------------------------------" << endl;


      system("pause");
      return 0;
    }

    =====================================================

    0 1 2 3 4 5 6 7 8 9
    ---------------------------------------
    9 8 7 6 5 4 3 2 1 0
    ---------------------------------------
    0 1 2 3 4 5 6 7 8 9
    ---------------------------------------
    4 3 2 1 0 9 8 7 6 5
    ---------------------------------------
    9 8 7 6 5 4 3 2 1 0
    ---------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    jquery获取浏览器URL参数
    jquery获取、设置、删除cookie
    jquery获取当前按钮、截取字符串、字符串拼接、动态循环添加元素
    Callback函数
    window.opener和window.open的使用
    JavaScript内置对象
    SeaJS:一个适用于 Web 浏览器端的模块加载器
    hihocoder 1388 &&2016 ACM/ICPC Asia Regional Beijing Online Periodic Signal
    Codeforces Round #373 (Div. 2)
    fzu 1759Super A^B mod C 指数循环节
  • 原文地址:https://www.cnblogs.com/herd/p/11011743.html
Copyright © 2011-2022 走看看