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. Genymotion 模拟器的sd卡的位置

    今天用genymotion测试一个例子,发现要用sdcard,虽然可以再DDMS的 File Explore 下看到 sdcard目录,也可以看到/mnt/sdcard 目录,但是往他那里传文件,建目 ...

  2. centos7修改hostname和hosts

    1.修改/etc/hostname vi /etc/hostname 打开之后的内容是: localhost.localdomain 把它修改成想要的名字就可以,比如:master 保存退出 2.修改 ...

  3. Flask路由系统与模板系统

    路由系统 @app.route('/user/<username>') @app.route('/post/<int:post_id>') @app.route('/post/ ...

  4. 利用AES算法加密数据

    准备工作: 模块安装问题: 首先在python中安装Crypto这个包 但是在安装模块后在使用过程中他会报错 下面是解决方法: pip3 install pycrypto 安装会报错 https:// ...

  5. JSR303验证

    转自:http://blog.csdn.net/lu930124/article/details/52587135 JSR-303是一个数据验证的规范,这里我不会讲这个规范是怎么回事,只会讲一下JSR ...

  6. sdut3138: N!(计算n!中结尾零的个数)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=3138 算法思想:在1-10两个数相乘要产 ...

  7. Web UI 自动化单个xpath抓取插件详解

    原文地址http://blog.csdn.net/kaka1121/article/details/51878346 单个控件获取 需求: 右键到某个控件上,就能获取到至多三个可以唯一定位该元素的相对 ...

  8. android 显示internet 图片

    try { HttpGet httpRequest = new HttpGet(edtUrl.getText() .toString()); HttpClient httpclient = new D ...

  9. Oracle数据库面试题(转)

    1. Oracle跟SQL Server 2005的区别? 宏观上: 1). 最大的区别在于平台,oracle可以运行在不同的平台上,sql server只能运行在windows平台上,由于windo ...

  10. 82. Remove Duplicates from Sorted List II(删除有序链表中的重复元素)

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...