C++常用数据结构

286 阅读1分钟

vector数组

变长数组,倍增思想(均摊o(1))

  • a.size()
  • a.empty()
  • a.clear()
  • a.front()
  • a.push_back(); a.pop_back()
  • a.begin(); a.end()迭代器
  • []
  • 比较运算:字典序

pair<int, int>

  • p.first; p.second
  • 比较运算:字典序
  • pair<int, pair<int, int>> p存3个元素

string字符串

  • size(), length()
  • empty()
  • clear()
  • substr(), c_str()

queue队列

  • size()
  • empty()
  • push()
  • front()
  • pop()
  • 无clear函数

priority_queue 优先队列(大根堆)

  • size()
  • empty()
  • push()
  • pop()
  • top()
  • priority_queue<int, vector<int>, greater<int>> h;小根堆
  • 无clear函数

stack栈

  • size()
  • empty()
  • push()
  • pop()
  • top()
  • 无clear函数

deque双端队列

加强版vector,很多函数,但是慢

  • size()
  • empty()
  • clear()
  • front()
  • back()
  • push_back(); pop_back()
  • push_front(); pop_front()
  • begin(), end()
  • []