1 Star 1 Fork 0

AlbertDarren / STL

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
set_multiset.cpp 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
AlbertDarren 提交于 2022-04-03 00:55 . first commit
/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <iostream>
#include <set>
#include <cstdlib>
#include <ctime>
using namespace std;
void showEach(auto &container)
{
cout << "The size of container is "<<container.size() << endl;
for(auto elem:container)
{
cout << elem << " ";
}
cout << endl;
}
void showIter(auto &container)
{
cout << "The size of container is "<<container.size() << endl;
for (auto i=container.begin(); i!=container.end() ; ++i )
{
cout << *i << " ";
}
cout << endl;
}
void findInt(auto container,int integer)
{
if (container.find(integer)!=container.end())
{
cout << integer<<" exists in the container" << endl;
}
else
{
cout << integer<<" doesn't exist in the container" << endl;
}
}
int main_26()
{
srand((unsigned int)time(nullptr));
set<int,greater<int>> int_set;
multiset<int> int_multiset;
int random_int;
for (int i=0; i<20 ; ++i )
{
random_int=rand()%50;
int_set.insert(random_int);
int_multiset.insert(random_int);
}
random_int=rand()%50;
cout << "The number of "<<random_int<<" in set is "<<int_set.count(random_int) << endl;
cout << "set" << endl;
showEach(int_set);
showIter(int_set);
findInt(int_set,random_int);
if (int_set.erase(random_int)>0)
{
cout << random_int<<" has been erased." << endl;
}
cout << "set has been cleared" << endl;
int_set.clear();
random_int=rand()%50;
cout << "The number of "<<random_int<<" in multiset is "<<int_multiset.count(random_int) << endl;
cout << "multiset" << endl;
showEach(int_multiset);
showIter(int_multiset);
findInt(int_multiset,random_int);
if (int_multiset.erase(random_int)>0)
{
cout << random_int<<" has been erased." << endl;
}
cout << "multiset has been cleared" << endl;
int_multiset.clear();
return 0;
}
C++
1
https://gitee.com/AlbertDarren_admin/stl.git
git@gitee.com:AlbertDarren_admin/stl.git
AlbertDarren_admin
stl
STL
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891