STL中会用到的函数

简介: 这段代码示例展示了C++中几种常用容器的使用,包括`vector`、`list`、`map`、`queue`、`deque`和`stack`。它涵盖了初始化、操作方法如添加、删除元素、排序、查找以及容器属性的查询等。同时,还提到了`algorithm`库中的`erase`、`sort`和边界查找函数。
#include<vector>
vector<int>s(n,ele)
    .assign(n,ele)
    .empty()
    .capacity()
    .size()
    .push_back(ele)
    .pop_back()
    insert(iterator pos,ele)
    erase(iterator begin,iterator end)
    clear()
    .front()
    .back()
    .reverve(int len)
    sort(iterator,iterator)
#include<list>//双向循环链表
list<int>l1(5,3)53
list<int>l2{
   1,2,3,4}
list<int>l2(l1)//迭代器中不能加数字
    .push_back()
    .pop_back()
    .find(iterator a,iterator b,3)->iterator
    .insert(pos,3)
    .erase(iterator,iterator)
    .remove(int)
    .unique()//去重
    .sort()
    .end()

#include<map>
map<int,char>mp//<key,value>
    .begin()
    .clear()
    .count(int)
    .empty()
    .end()
    .erase(element)
    .size()
    .find(int)->iterator
    mp.insert(map<int,char>::value_type(5,'d'))
#include<queue>//队列
    queue<int>q1
    .back()
    .empty()
    .front()
    .pop()
    .push()
    .size()
#include<deque>
    queue<type>v(n,value)
    queue<type>v{
   ....}
    .end()
    .begin()
    .empty()
    .at(index)->element
    .front()
    .back()
    .assign()
    .push_back()
    .push_front()
    .pop_back()
    .pop_front()
#include<stack>
    .push()
    .pop()
    .top()
    .empty()
    .size()
#include<algorithm>
    erase()
    sort()
    upper_bound(it,it,int val)返回第一个大于等于val的迭代器
    lower_bound(it,it,int val)小于等于//前提是有序
    int ants=unique(arr,arr+7)-arr;//unique()返回最后无重复数的地址,是个迭代器
目录
相关文章
|
5天前
|
C++
stl中copy注意的地方
stl中copy注意的地方
|
9月前
|
算法 C++ 容器
STL算法篇之拷贝修改类算法
STL算法篇之拷贝修改类算法
|
9月前
|
C++ 容器
STL 基本操作(包含所有基本的函数功能)
STL 基本操作(包含所有基本的函数功能)
67 0
|
算法 搜索推荐 C++
第九章(14):STL之常用拷贝和替换算法
第九章(14):STL之常用拷贝和替换算法
第九章(14):STL之常用拷贝和替换算法
|
算法 编译器 C语言
【STL算法】for_each源码刨析及函数对象本质刨析
【STL算法】for_each源码刨析及函数对象本质刨析
121 0
【STL算法】for_each源码刨析及函数对象本质刨析
|
存储 算法 C++
分块刨析从函数原型到分块实现C++STL(vector)
分块刨析从函数原型到分块实现C++STL(vector)
分块刨析从函数原型到分块实现C++STL(vector)
|
存储 算法 安全
初阶C++——STL——string类、vector类和list类(使用方法+模拟实现+测试+思路分析)
Alexander Stepanov、Meng Lee 在惠普实验室完成的原始版本,本着开源精神,他们声明允许任何人任意运用、拷贝、修改、传播、商业使用这些代码,无需付费。唯一的条件就是也需要向原始版本一样做开源使用。 HP 版本--所有STL实现版本的始祖。
319 0
初阶C++——STL——string类、vector类和list类(使用方法+模拟实现+测试+思路分析)
C++栈的基本操作及原理和STL函数
目录 文章目录 前言 一、栈是什么? 二、使用步骤 1.栈的结构定义 2.构造一个栈 3.入栈 4.出栈 5.返回栈顶空间 三、STL 总结
184 0
C++栈的基本操作及原理和STL函数
|
算法 C++
STL算法——内建函数对象
STL算法——内建函数对象
STL算法——内建函数对象