zoukankan      html  css  js  c++  java
  • STL 常用容器

     1     //动态数组
     2     vector<int> theVector;
     3     theVector.push_back(1);
     4     theVector.push_back(2);
     5     theVector.push_back(3);
     6     theVector.pop_back();
     7     vector<int>::iterator itVector;
     8     cout << "vector" << endl;
     9     for(itVector = theVector.begin(); itVector != theVector.end(); itVector++)
    10     {
    11         cout << *itVector << endl;
    12     }
    13 
    14     //双向链表
    15     list<int> theList;
    16     theList.push_back(1);
    17     theList.push_front(2);
    18     list<int>::iterator itList;
    19     cout << "list" << endl;
    20     for(itList = theList.begin(); itList != theList.end(); itList++)
    21     {
    22         cout << *itList << endl;
    23     }
    24 
    25     //
    26     stack<int> theStack;
    27     theStack.push(1);
    28     theStack.push(2);
    29     theStack.push(3);
    30     theStack.pop();
    31     cout << "stack" << endl;
    32     while(!theStack.empty())
    33     {
    34         cout << theStack.top() << endl;
    35         theStack.pop();
    36     }
    37 
    38     //队列
    39     queue<int> theQueue;
    40     theQueue.push(1);
    41     theQueue.push(2);
    42     theQueue.push(3);
    43     theQueue.pop();
    44     cout << "queue" << endl;
    45     while(!theQueue.empty())
    46     {
    47         cout << theQueue.front() << endl;
    48         theQueue.pop();
    49     }
    50 
    51     //红黑树
    52     map<int, string, less<int> > theMap;//模版最后位置加空格
    53     theMap.insert(map<int, string, less<int> >::value_type(0,"Zero"));
    54     theMap.insert(map<int, string, less<int> >::value_type(1,"One"));
    55     theMap.insert(map<int, string, less<int> >::value_type(2,"Two"));
    56     map<int, string, less<int> >::iterator itMap;
    57     cout << "map" << endl;
    58     for(itMap = theMap.begin(); itMap != theMap.end(); itMap++)
    59     {
    60         cout << (*itMap).second << endl;
    61     }
  • 相关阅读:
    Web大文件上传断点续传解决方案
    STL 源代码剖析 算法 stl_algo.h -- rotate
    BZOJ 1260 CQOI2007 涂色paint 动态规划
    Shiro学习(总结)
    数组与指针
    Doing Homework again(杭电1789)
    leetCode 75.Sort Colors (颜色排序) 解题思路和方法
    hdu 4786 Fibonacci Tree(最小生成树)
    Havel--Hakimi定理推断可图化 python
    最近小感——一个残疾人写的操作系统
  • 原文地址:https://www.cnblogs.com/luzhiyuan/p/3932474.html
Copyright © 2011-2022 走看看