zoukankan      html  css  js  c++  java
  • 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
    ------------------------------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    i++与++i
    acm语录
    c# SQL2000 access 远程连接操作
    C# 四舍五入函数
    WINDOWS 2003 远程桌面记录登陆IP
    jquery 资源
    php google baidu 分页
    Solutions to place plus or minus signs to a nonzero digits sequence 123456789 so that result of thus described arithmetic opera
    VB获取网页下文字的链接地址
    php cache 缓存方法类一
  • 原文地址:https://www.cnblogs.com/herd/p/11008924.html
Copyright © 2011-2022 走看看