C++STL 库中set容器应用
#include<iostream> #include<cstdio> #include<set> using namespace std; set<int> a; int main() { //插入元素 a.insert(1); a.insert(3); a.insert(5); //用迭代器遍历容器; set<int>::iterator it; for(it=a.begin(); it!=a.end(); it++) { cout<<*it<<endl; } //find(key_value) 若查找成功返回迭代器位置,否则返回容器最后一个元素的后一个位置 if(a.find(1)!=a.end()) { cout<<"find success"<<endl; } else { cout<<"losing finding"<<endl; } //count(key_value) 若查找成功返回true, 否则返回false if(a.count(1)==true) { cout<<"find success"<<endl; } else { cout<<"losing finding"<<endl; } //size()返回容器中元素个数 cout<<"set中的元素个数是"<<a.size()<<endl; //clera()将容器清空 a.clear(); //empty()判断容器是否为空 if(a.empty()) { cout<<"set is empty"<<endl; } else { cout<<"set is not empty"<<endl; } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 电商平台中订单未支付过期如何实现自动关单?
· 用 .NET NativeAOT 构建完全 distroless 的静态链接应用
· 为什么构造函数需要尽可能的简单
· 探秘 MySQL 索引底层原理,解锁数据库优化的关键密码(下)
· 大模型 Token 究竟是啥:图解大模型Token
· 瞧瞧别人家的限流,那叫一个优雅!
· 1.net core 工作流WorkFlow流程(介绍)
· 一文彻底搞懂 MCP:AI 大模型的标准化工具箱
· 面试官:如果某个业务量突然提升100倍QPS你会怎么做?
· .NET 平台上的开源模型训练与推理进展