2017-08-20 15:21:31

writer:pprp

set集合容器使用红黑树的平衡二叉树检索树,不会将重复键值插入,检索效率高 logn

检索使用中序遍历,所以可以将元素从小到大排列出来

/*
name : usage of Set
writer : pprp
declare : null
date ; 2017/8/20
*/
#include <bits/stdc++.h> using namespace std; void print(set<int> &s)
{
set<int>::iterator it;
for(it = s.begin(); it != s.end(); it++)
{
cout << *it <<" ";
}
cout << endl;
} void printms(multiset<int> &ms)
{
set<int>::iterator it;
for(it = ms.begin() ; it != ms.end() ; it++)
{
cout << *it << " ";
}
cout << endl;
} int main()
{
set<int> s;
//set的建立
for(int i = ; i <= ; i++)
{
pair<set<int>::iterator, bool> p = s.insert(i);//用于判断是否插入成功
if(p.second)
cout << "successful" << endl;
else
cout << "can not insert the same word" << endl;
} set<int> s2(s);//初始化 print(s2); s2.erase(s2.begin()); //只把头删除了 print(s2); s2.erase(s2.erase()); //把头和值位10的点都删除了 print(s2); //完成对某个元素的查找
set<int>::iterator i;
i = s2.find();
if(i != s2.end())
{
cout << "find" << endl;
}
else
cout << "can not find" << endl; //测试是否可重复
multiset<int> ms;
for(int i = ; i <= ; i = i + )
{
ms.insert(i);
ms.insert(i+);
ms.insert(i+);
ms.insert(i+);
} //测试是否有序
ms.insert(-);
ms.insert(); printms(ms); //查找元素
int v = ;
multiset<int>::iterator t = ms.find(v);
if(t != ms.end())
{
cout << *t << endl;
} //查找相同元素
pair<multiset<int>::iterator,multiset<int>::iterator> cmp = ms.equal_range(v); cout << *cmp.first << endl; //第一个大于等于该元素的值
cout << *cmp.second << endl; //第一个大于该元素的值 cout << ms.count() << endl;//集合中元素为6的个数 multiset<int>::iterator ii; ii = ms.lower_bound();
cout << *ii << endl;
ii = ms.upper_bound();
cout << *ii << endl; return ;
}

STL set集合用法总结(multiset)的更多相关文章

  1. C++中的STL中map用法详解(转)

    原文地址: https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html C++中的STL中map用法详解   Map是STL的一个关联容器,它提供 ...

  2. STL的其他用法(adjacent_find, find_first_of, sort_heap, merge, binary_search)总结

    2017-08-20 17:26:07 writer:pprp 1.adjacent_find() 下面是源码实现: template <class ForwardIterator> Fo ...

  3. C++-STL:vector用法总结

    目录 简介 用法 1. 头文件 2. vector的声明及初始化 3. vector基本操作 简介 vector,是同一类型的对象的集合,这一集合可看作可变大小的数组,是顺序容器的一种.相比于数组,应 ...

  4. STL vector+sort排序和multiset/multimap排序比较

    由 www.169it.com 搜集整理 在C++的STL库中,要实现排序可以通过将所有元素保存到vector中,然后通过sort算法来排序,也可以通过multimap实现在插入元素的时候进行排序.在 ...

  5. STL的常用用法、函数汇总(不定时更新)

    隶书文字为原创. 1.vector 在c++中,vector是一个十分有用的容器,下面对这个容器做一下总结. 1 基本操作 (1)头文件#include<vector>. (2)创建vec ...

  6. STL中map用法

    Map是 STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于 这个特性,它完成有可能在我们处理一对一数据的 ...

  7. [STL] SET实用用法

    背景 今天考试深受平衡树之害,可以参见上一篇博客,想到了set却苦于实用的不熟练.同时QTY询问set的具体用法,所以写这篇博客,同时留作自用. 分类 参看了一下网上其他set博客,上来都是长篇大论概 ...

  8. C++中的STL中map用法详解

    Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据 处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时 ...

  9. (转载) STL中map用法详解

    Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候 ...

随机推荐

  1. LeetCode_Add Two Numbers

    题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...

  2. replace未全局替换的坑

    今天是名副其实的周六.悠闲了一早上(太阳). 真是人在家中坐,BUG自天上来.哈哈其实也不是自天上来,还是自己之前埋下的雷. 所以修复完线上的bug,我脑中立刻浮现出两件还需要做的事情: 一,就是我现 ...

  3. TypeScript教程

    汇智课堂 地址  http://www.hubwiz.com/course/55b724ab3ad79a1b05dcc26c/ TypeScript是一种由微软开发的自由和开源的编程语言.它是Java ...

  4. Android training–android studio

    又重新开始学习android开发了,希望这次不是三分钟热度.之前是利用eclipse+ADT来开发的,官网上建议用Android Studio.刚好重装了系统,升级了内存.于是下个studio来学学. ...

  5. JavaScript日期处理

    一.Date类型 在讲述常见日期问题之前,先梳理一下Date类型的方法. ECMAScript中的Date类型使用自UTC(Coordinated in Universal Time,国际协调时间)1 ...

  6. django生产环境部署

    测试环境:linux centos7下 1.安装uwsgi python3下安装: pip3 install uwsgi python2下安装: pip install uwsgi 如果是系统自带的p ...

  7. PAT 1048 Find Coins[比较]

    1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other p ...

  8. PKU 1201 Intervals(差分约束系统+Spfa)

    题目大意:原题链接 构造一个集合,这个集合内的数字满足所给的n个条件,每个条件都是指在区间[a,b]内至少有c个数在集合内.问集合最少包含多少个点.即求至少有多少个元素在区间[a,b]内. 解题思路: ...

  9. JQueryEasyUI easyui-combobox 单击文本区域显示下拉菜单

    //单击内容框弹出下拉菜单 $(".combo").click(function (e) { if (e.target.className == 'combo-text valid ...

  10. cgwin的ssh错误解决办法

    参考博客    http://hi.baidu.com/luckygirl/item/bd00a6d8a05c310d20e25039 方法一(推荐): 修改/etc/passwd文件,在其中加入 s ...