版本比较
复赛笔记(有问题请私信)
正文
增加 25 行删除 25 行
122345616 行未改动2324252627272829293031323334353636373839406 行未改动474849505151525354558 行未改动646566676868697071723 行未改动7677787980818081828384852 行未改动8889909192929394959697969798991001012 行未改动104105106107108108109110111112113114115116117116117118119120120121122123123124125126125126127128129130131132132133134135135136137138139140141142143143144145146147148149150151151152153154155156156157158159160161162162163164164165166```cpp//一、常用函数。 //一、常用函数。
//1.swap()交换两个变量的值#include <algorithm>using namespace std;16 行未改动#include <algorithm>#include <vector>using namespace std;vector<int> vec(10);int main(){fill(vec.begin(),vec.end(),5);}//vec的所有元素为5 int main(){fill(vec.begin(),vec.end(),5);}//vec的所有元素为5
//4.atoi()将C风格字符串转化为整数 //4.atoi()将C风格字符串转化为整数#include <cstdlib>using namespace std;const char* str="12345";int main(){int num=atoi(str);}//num=12345
//5.stoi()将string转化为整数#include <string> #include <string>using namespace std;string s="12345";int main(){int num=stoi(s);}//num=12345
6 行未改动
//7.lower_bound()与upper_bound//lower_bound:在有序范围内查找一个不小于给定值的元素//upper_bound:在有序范围内查找一个大于给定值的元素//基于二分查找实现 //基于二分查找实现#include <algorithm>#include <vector>using namespace std;vector<int> vec={1,2,4,4,5,6};8 行未改动}
//8.reverse()反转指定范围内的元素顺序#include <algorithm>#include <vector> #include <vector>vector<int> vec={1,2,3,4,5};int main(){reverse(vec.begin(),vec.end());}//vec变为{5,4,3,2,1}
#include <algorithm>3 行未改动int main(){reverse(s.begin(),s.end());}//s变为"olleh"
//9.sort()对数组、vector、list进行排序#include <algorithm>#include <vector> #include <iostream> #include <vector>#include <iostream>using namespace std;int main(){ vector<int> vec={4,2,3,5,1};2 行未改动 { cout<<num<<" "; } return 0; //输出:1 2 3 4 5 //输出:1 2 3 4 5}
#include <algorithm>#include <vector> #include <iostream> #include <vector>#include <iostream>using namespace std;int main(){ vector<int> vec={4,2,3,5,1};2 行未改动 { cout<<num<<" "; } return 0; //输出:5 4 3 2 1 //输出:5 4 3 2 1}
//二、数据结构。
//1.list//底层:双向链表//插入:push_back(),push_front(),irser()//删除:pop_back(),pop_front(),erase(),femove() //查找:find()(需要配合<algorithm>库) //删除:pop_back(),pop_front(),erase(),femove()//查找:find()(需要配合<algorithm>库)//清空:clear()//判断空:empty()//遍历:使用迭代器begin()到end() //遍历:使用迭代器begin()到end()
//2.vector//底层:动态数组 //底层:动态数组//插入:push_back(),insert()//删除:pop_back(),erase(),clear() //查找:find()(需要配合<algorithm>库) //删除:pop_back(),erase(),clear()//查找:find()(需要配合<algorithm>库)//清空:clear()//判断空:empty()//遍历:使用迭代器begin()到end()
//3.stack//底层:栈 //底层:栈//插入:push()//删除:pop()//访问栈顶:top() //访问栈顶:top()//判断是否为空:empty()//大小:size()
//4.queue//底层:deque(双端队列)//插入:push()//删除:pop()//访问队首:front() //访问队首:front()//判断是否为空:empty()//大小:size()
//5.priority_queue//底层:堆(默认最大堆)//插入:push()//删除:pop()//访问最大元素:top() //访问最大元素:top()//判断是否为空:empty()//大小:size()
//6.map/multimap//底层:红黑树 //底层:红黑树//插入:insert(),operator[]//删除:erase(),clear()//查找:find()//判断是否存在:使用find()返回的迭代器//清空:clear()//判断空:empty() //判断空:empty()//统计元素个数:count()(map只返回0或1)//遍历:使用迭代器 begin()到end() //遍历:使用迭代器 begin()到end()```更新中......