一、概念

  1. 标准模板库(Standard Template Library,STL),是 ISO C++ 标准库的一部分,包含各种数据结构和算法
  2. STL 的组成部分:容器(Containers)、算法(Algorithms)、迭代器(Iterator)
  3. 容器的分类
    1. Sequential:array、vector、deque(双头队列)、forward_list(单向链表)、list(双向链表)
    2. Associative:set(collection of unique keys)、map(collection of key-value maps)、multiset、multimap
    3. Unordered Associative:unordered_set、unordered_map、unordered_multiset、unordered_multimap
    4. Adaptors:stack、queue、priority_queue

二、Vector

  1. 概述

  2. 构造函数(Constructors)

  3. 获取大小

  4. 迭代器

  5. 元素访问

    int main()
    { 
    	list<string> s; 
    	s.push_back("hello"); 
    	s.push_back("world"); 
    	list<string>::iterator p;
    	for(p = s.begin(); p != s.end(); p++) 
    	cout << *p <<" ";
    }
    
  6. 添加 / 删除 / 查找

  7. 其他

三、List

  1. 操作

    
    x.front()
    x.back()
    x.push_back(item)
    x.push_front(item)
    x.pop_back()
    x.pop_front()
    x.erase(pos1, pos2)
    x.count()
    x.reverse(size)
    x.resize()
    
  2. 列表元素大小不确定,因此使用迭代器对列表遍历时,只能使用 == 或 != 比较运算符

  3. C++ 无法为列表预留空间,所以列表没有 capacity() 函数

四、Map

  1. 映射(Maps)是一种关联容器(类似 Python 中的字典),用于存储由(Keys)及其映射值构成的元素,以特定顺序排列
  2. 键常用于排序或识别唯一的元素,映射值存储对应键的内容