代码拉取完成,页面将自动刷新
/**
* @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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。