set c++

#include <bits/stdc++.h>
using namespace std;
int main(){
	set<int> s;
	set<int>::iterator it;
	int a[10];
	for(int i=0; i<10; i++) a[i]=i*2;
	//insert();
	for(int i=0; i<10; i++)
		s.insert(i);//插入单个值; 
	s.insert(a+4, a+9);//插入多个值; 
	//find();
	int x;
	cin >> x;
	if(s.find(x)!=s.end()) cout << "yes\n";
	else cout << "no\n";
	//count();
	cout << s.count(x) << endl;
	//erase();
	it=s.find(x);
	//s.erase(it);//删除it指向的值;
	//s.erase(x);//删除x;
	//s.erase(s.begin(), s.end()); 
	//遍历; 
	cout << "----\n";
	for(it=s.begin(); it!=s.end(); it++){
		cout << *it << endl;
	} 
	cout << "---\n";
	//size();
	cout << s.size() << endl;
	//lower_bound();返回第一个大于等于x的数的位置; 
	it=s.lower_bound(x);
	cout << *it << endl;
	//upper_bound();返回第一一个大于x的数的位置;
	it=s.upper_bound(x);
	cout << *it << endl;
	s.clear();
	cout << s.empty();
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值