既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
}
//有序关联容器
class Student
{
public:
Student(int id = 0, string name = nullptr)
:_id(id), _name(name)
{}
bool operator<(const Student &stu)const
{
return this->_id < stu._id;
}
private:
int _id;
string _name;
friend ostream& operator<<(ostream &out, const Student &stu);
};
ostream& operator<<(ostream &out, const Student &stu)
{
out << "id: " << stu._id << "name: " << stu._name << endl;
return out;
}
int main()
{
setset1;
for (int i = 0;i < 20;++i)
{
set1.insert(rand() % 100);
}
for (int v : set1)
{
cout << v << " ";
}
cout << endl;
multiset<Student>set2;
set2.insert(Student(1, "wyl"));
set2.insert(Student(2, "yyz"));
set2.insert(Student(1, "wyl"));
for (auto it = set2.begin();it != set2.end();it++)
{
cout << \*it << endl;
}
return 0;
}
\*\*总结:
1、单集合容器不允许关键字重复,多集合容器允许重复
2、在容器中不能修改元素
3、有序关联容器会进行排序,无序关联容器不会进行排序
\*\*
## map
map底层存放的是键值对[key,value]
struct std::pqir<int const,int>
{
int const key;
int value;
}
增
map1.insert(make_pair(1000, “wyl”));
map1.insert({ 1001,“wyl1” });
map1.insert(pair<int,string>(10, “we”));
map的下标运算符重载函数分为两步:
1、查询是否存在
2、如果不存在则插入一对键值对。
其余操作和set无差别
class Student
{
public:
Student(int id = 0, string name = nullptr)
:_id(id), _name(name)
{}
bool operator<(const Student &stu)const
{
return this->_id < stu._id;
}
private:
int _id;
string _name;
friend ostream& operator<<(ostream &out, const Student &stu);
};
ostream& operator<<(ostream &out, const Student &stu)
{
out << "id: " << stu._id << "name: " << stu._name << endl;
return out;
}
int main()
{
map<int, Student>map1;
map1.insert({ 1000,Student(1000,“wyl1”) });
map1.insert({ 1001,Student(1001,“wyl2”) });
map1.insert({ 1002,Student(1002,“wyl3”) });
map1.insert({ 1003,Student(1003,“wyl4”) });
cout << map1[1000] << endl;
auto it5 = map1.find(1000);
cout << it5->first<second << endl;
it5 = map1.begin();
for (;it5 != map1.end();it5++)
{
cout << “key:” << it5->first << “value:” << it5->second << endl;
}
unordered_map<int, string>map1;
map1.insert(make\_pair(1000, "wyl"));
map1.insert({ 1001,"wyl1" });
map1.insert(pair<int,string>(10, "we"));
//返回键值表的个数
cout << map1.size() << endl;
cout << map1[1000] << endl;
map1.erase(1001);
//operator[]
//1、查询
//2、如果key不存在,他会插入一对数据[key,string()]
map1[2000] = "王煜龙";
cout << map1[2000] << endl;
auto it2 = map1.find(1000);
cout << it2->first << it2->second << endl;
it2 = map1.begin();
for (;it2 != map1.end();it2++)
{
cout << it2->first << ":" << it2->second << endl;
}
return 0;
}
### 海量数据查重去重
#define SIZE 100
int main()
{
int arr[SIZE] = { 0 };
for (int i = 0;i < SIZE;++i)
{
arr[i] = rand() % 10;
}
unordered_map<int, int>map1;
for (int k : arr)
{
/*
auto it = map1.find(k);
if (it == map1.end())
{
map1.insert({ k,1 });
}
else
{
it->second++;
}
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!**
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新