• C++ STL swap_range


    #include <iostream>
    #include <vector>
    #include <deque>
    #include <algorithm>

    using namespace std;


    int main()
    {
      vector<int> vec1;
      deque<int> deq1;

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

      for (int k=10;k<23;k++)
      {
        deq1.push_back(k);
      }

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

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

      swap_ranges(vec1.begin(), vec1.end(), deq1.begin());

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

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

      system("pause");
      return 0;
    }

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

    0 1 2 3 4 5 6 7 8 9
    ------------------------------------------------------------
    10 11 12 13 14 15 16 17 18 19 20 21 22
    ------------------------------------------------------------
    10 11 12 13 14 15 16 17 18 19
    ------------------------------------------------------------
    0 1 2 3 4 5 6 7 8 9 20 21 22
    ------------------------------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    深入Celery之使用队列以及优先级提高响应
    Redis真的那么好用吗?
    Python中的绝对导入和相对导入
    七个可以提升python程序性能的好习惯
    log封装-python3
    通过zoopkeeper客户端查看Kafka主题实例ip(需要知道任意一个zk地址)
    python3-kafka生产者可入json数据(pykafka)
    python3-数据库插入数据(pymysql)
    unittest显示用例名称
    appium(1)-获取APPdriver封装
  • 原文地址:https://www.cnblogs.com/herd/p/11008924.html
Copyright © 2020-2023  润新知