• C++ STL copy copy_backward


    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <functional>
    #include <list>

    using namespace std;


    int main()
    {
      list<int> list1;
      for (int k=0;k<10;k++)
      {
        list1.insert(list1.end(),k);
      }

      list<int>::iterator list_iter1;
      for (list_iter1 = list1.begin();list_iter1 != list1.end();++list_iter1)
      {
        cout << *list_iter1 << " ";
      }
      cout << endl;
      cout << "----------------------------------------------------------" << endl;

      vector<int> vec1(list1.size()*2);
      vector<int>::iterator vec_iter1;

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

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

      copy_backward(list1.begin(),list1.end(),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
    ----------------------------------------------------------
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    ----------------------------------------------------------
    0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0
    ----------------------------------------------------------
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
    ----------------------------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    06 Python字符编码与文件处理
    05 基本数据类型+五大数据类型
    04 Python入门学习-流程控制(if else elif while for)
    《算法导论》学习总结 — XX.第22章 图的基本算法
    Google在KDD2013上关于CTR的一篇论文
    二项堆
    B树、B+树、B*树
    mysql sql语句大全
    红黑树
    《算法导论》学习总结 — 13. 第13章 红黑树(2)
  • 原文地址:https://www.cnblogs.com/herd/p/11007450.html
Copyright © 2020-2023  润新知