set容器
阿新 • • 發佈:2020-10-12
stl 的set容器很好用,非常有必要掌握
// ascending red black tree // cross set_intersection difference set_difference union set_union multiset<int>st;//多重集 s.begin();//返回集合第一個元素 s.end(); s.clear(); s.empty(); s.insert(); s.erase(); s.size(); //建立 set<int>s; set<int,greater<int > >s2;//帶大於比較器的集合(預設為小於)int a[5]={1,2,3,4,5}; set<int > s(a,a+5);//用陣列初始化 set<int > s(setc.begin(),setc.end());//用集合初始化 set<int > sete(sete);//拷貝 //插入 s.insert(_x); s.insert(a,a+5); //刪除 s.erase(_x); s.clear(); //修改 :刪除後再新增 //查詢 s.find(_x);//存在? 地址:s.end(); s.lower_bound(_x); s.upper_bound(); //自定義比較函式 struct cmp{bool operator () (const int &a,const int &b){ return a>b; } } set<int,cmp>s; //指標 set<int>::iterator it; auto it; next(it)//it 的下一個 prev(it)//it 的上一個