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++ 容器
C++ STL:空间配置器源码解析
C++ STL:空间配置器源码解析
|
4月前
|
算法 Linux C语言
7.学习STL和string类:版本、组件、构造、操作及应用
7.学习STL和string类:版本、组件、构造、操作及应用
|
5月前
|
C++
stl中copy注意的地方
stl中copy注意的地方
|
5月前
|
C++ 容器
【C++】STL容器——探究不同 [ 迭代器 ] 种类&在STL中的使用方式(15)
【C++】STL容器——探究不同 [ 迭代器 ] 种类&在STL中的使用方式(15)
|
5月前
|
编译器 C++
C++之STL库:string类(用法列举和总结)
C++之STL库:string类(用法列举和总结)
|
12月前
|
C++
利用stl的集合类函数 操作mfc数组
利用stl的集合类函数 操作mfc数组
|
算法 C++ 开发者
8.1 C++ STL 变易拷贝算法
C++ STL中的变易算法(Modifying Algorithms)是指那些能够修改容器内容的算法,主要用于修改容器中的数据,例如插入、删除、替换等操作。这些算法同样定义在头文件 `<algorithm>` 中,它们允许在容器之间进行元素的复制、拷贝、移动等操作,从而可以方便地对容器进行修改和重组。
70 0
|
算法 C++ 容器
STL算法篇之拷贝修改类算法
STL算法篇之拷贝修改类算法
|
C++ 容器
STL 基本操作(包含所有基本的函数功能)
STL 基本操作(包含所有基本的函数功能)
83 0
|
算法 编译器 C语言
【STL算法】for_each源码刨析及函数对象本质刨析
【STL算法】for_each源码刨析及函数对象本质刨析
163 0
【STL算法】for_each源码刨析及函数对象本质刨析