set集合
2024-12-14 15:18:50
发布于:北京
一、定义:
include <set>
set <数据类型> 名称;
例:
set <int> se;
二、添加元素:
名称.insert (元素);
例:
se.insert (1);
三、遍历:
1、迭代器:
for (it = se.begin (); it != se.end; it ++) cout << *it << ' ';
cout << endl;
2、auto:
for (auto it : se) cout << it << ' ';
cout << endl;
三、常用函数:
1、v.erase (x) 删除v中所有的x;
2、v.find (x) 在v中查找x,返回一个迭代器(地址),没有则返回“end ()”;
3、v.empty () 判断v是否为空。
这里空空如也
有帮助,赞一个