zoukankan      html  css  js  c++  java
  • *** reverse算法的应用

    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <vector>
    #include <list>
    #include <deque>
    using namespace std;
    
    int main()
    {
        // demonstrate reverse an int array
        int a[4] = {3,2,4,1};
        
        reverse<int [4]>(a,a+4);
        
        cout << "After reverse int a[4]:" << endl;
        for (int i=0; i<4; i++)
        {
            cout << a[i] << endl;
        }
        
        // demonstrate reverse a vector
        vector<string> v;
        v.push_back("Jason");
        v.push_back("Becky");
        v.push_back("Jessie");
        v.push_back("Alex");
        
        reverse<vector<string>::iterator>(v.begin(), v.end());
    
        cout << "After reverse vector v:" << endl;
        for (vector<string>::iterator i=v.begin(); i!=v.end(); i++)
        {
            cout << (*i) << endl;
        }
        
        // demonstrate reverse a list
        list<int> l;
        l.push_back(10);
        l.push_back(20);
        l.push_back(30);
        l.push_back(40);
        reverse<list<int>::iterator>(l.begin(), l.end());
        for (list<int>::iterator i=l.begin(); i!=l.end(); i++)
        {
            cout << (*i) << endl;
        }
        
        // demonstrate reverse a deque
        deque<int> d;
        d.push_back(100);
        d.push_back(200);
        d.push_back(300);
        d.push_back(400);
        reverse<deque<int>::iterator>(d.begin(), d.end());
        for (deque<int>::iterator i=d.begin(); i!=d.end(); i++)
        {
            cout << (*i) << endl;
        }
        
        return 0;
    }
  • 相关阅读:
    java循环结构
    java 修饰符
    java变量类型
    java对象和类
    java 环境配置及开发工具
    easy_install 和 pip
    比利牛斯獒犬 flask web
    vim 命令
    vim vi Ubuntu 设置
    Python interview_python
  • 原文地址:https://www.cnblogs.com/superrunner/p/10216528.html
Copyright © 2011-2022 走看看