set 容器
#include <iostream>
#include <set>
#include <algorithm>
template <typename T>
void display(const std::set<T> &arr){
for (const auto &i: arr)
std::cout << i << " ";
std::cout << std::endl;
}
void test1()
{
std::set<int> s1 {1, 2, 3, 4, 5};
s1 = {6, 7, 7, 1, 1, 5, 4, 3, 4, 4, 5, 5, 5, 5};
display(s1);
s1.insert(10);
if (s1.count(10))
std::cout << "已找到" << std::endl;
else
std::cout << "未找到" << std::endl;
auto it = s1.find(10);
if (it !=s1.end())
std::cout << "已找到" << *it << std::endl;
s1.clear();
}
void test2()
{
std::set<std::string> s1 {"A", "B", "C", "D", "E"};
auto result = s1.insert("F");
std::cout << std::boolalpha;
std::cout << "first:" << *(result.first) << std::endl;
std::cout << "second:" << result.second << std::endl;
result = s1.insert("A");
std::cout << std::boolalpha;
std::cout << "first:" << *(result.first) << std::endl;
std::cout << "second:" << result.second << std::endl;
}
int main()
{
test2();
}