set和map的底层模板是红黑树,可以有不同的键值和实值,关于增删改查,迭代器的使用都在代码里面,亲手尝试更方便记忆

#include <iostream>
#include <map>
#include <algorithm>

//#include <functional>//不知道用来干什么

using namespace std;
void fun(pair<int,char>pr){
cout << pr.first << "-" << pr.second << " ";
}
int main()
{

map<int,char>imp;
imp.insert(pair<int,char>(3,'a'));
imp.insert(pair<int,char>(2,'b'));
imp.insert(pair<int,char>(1,'c'));
imp.insert(pair<int,char>(4,'f'));
imp.insert(pair<int,char>(5,'g'));
imp[10]='i';

//imp.insert(pair<int,char>(2,'a'));
map<int,char,less<int> >imp1(imp);
map<int,char>imp2(imp1.begin(),imp1.end());
map<int,char>::iterator ite=imp2.begin();
imp.clear();
ite++;
imp.insert(ite,imp2.end());
imp.swap(imp1);
//cout << imp.size() << " " << imp.count(2) << " " << imp.empty() << endl;
ite=imp.find(2);
ite=imp.upper_bound(1);//>,返回迭代器
ite=imp.lower_bound(3);//<=,返回迭代器
//cout << ite->second << endl;
//键值不可修改,实值可以修改

//删
//imp.erase(2);
map<int,char>::iterator ite1=imp.find(3);
map<int,char>::iterator ite2=imp.find(4);
//imp.erase(ite1,ite2);//ite1到ite2的前一个元素
//imp.erase(ite);
//imp.clear();

//cout << imp.max_size() << endl;

//改
//imp[3]='w';
//cout <<imp[3] << endl;

//查
//ite=imp.find(2);//若找不到,指向end()
//cout << imp[2] << " " << ite->second << endl;
//cout << imp[11] << endl;//找不到就不输出
//for_each(imp.begin(),imp.end(),fun);
cout << endl;

map<int,char,greater<int> >rimp(imp.begin(),imp.end());
for_each(rimp.begin(),rimp.end(),fun);
cout << endl;
pair<map<int,char>::iterator,map<int,char>::iterator> pre;
pre=imp.equal_range(2);
cout << pre.first->first << endl;
cout << pre.second->first << endl;
/*
//key_comp()
map <int, int, less<int> > m1;
map <int, int, less<int> >::key_compare kc1 = m1.key_comp( ) ;
bool result1 = kc1( 2, 3 ) ;
if( result1 == true )
{
cout << "kc1( 2,3 ) returns value of true, "
<< "where kc1 is the function object of m1."
<< endl;
}
else
{
cout << "kc1( 2,3 ) returns value of false "
<< "where kc1 is the function object of m1."
<< endl;
}

map <int, int, greater<int> > m2;
map <int, int, greater<int> >::key_compare kc2 = m2.key_comp( );
bool result2 = kc2( 2, 3 ) ;
if( result2 == true )
{
cout << "kc2( 2,3 ) returns value of true, "
<< "where kc2 is the function object of m2."
<< endl;
}
else
{
cout << "kc2( 2,3 ) returns value of false, "
<< "where kc2 is the function object of m2."
<< endl;
}
*/

/*
equal_range()//在algorithm头文件,map头文件
typedef map <int, int, less<int> > IntMap;
IntMap m1;
map <int, int> :: const_iterator m1_RcIter;
typedef pair <int, int> Int_Pair;

m1.insert ( Int_Pair ( 1, 10 ) );
m1.insert ( Int_Pair ( 2, 20 ) );
m1.insert ( Int_Pair ( 3, 30 ) );

pair <IntMap::const_iterator, IntMap::const_iterator> p1, p2;
p1 = m1.equal_range( 2 );

cout << "The lower bound of the element with "
<< "a key of 2 in the map m1 is: "
<< p1.first -> second << "." << endl;

cout << "The upper bound of the element with "
<< "a key of 2 in the map m1 is: "
<< p1.second -> second << "." << endl;

// Compare the upper_bound called directly
m1_RcIter = m1.upper_bound( 2 );

cout << "A direct call of upper_bound( 2 ) gives "
<< m1_RcIter -> second << "," << endl
<< "matching the 2nd element of the pair"
<< " returned by equal_range( 2 )." << endl;

p2 = m1.equal_range( 4 );

// If no match is found for the key,
// both elements of the pair return end( )
if ( ( p2.first == m1.end( ) ) && ( p2.second == m1.end( ) ) )
cout << "The map m1 doesn't have an element "
<< "with a key less than 40." << endl;
else
cout << "The element of map m1 with a key >= 40 is: "
<< p2.first -> first << "." << endl;
}
*/
return 0;
}

stl_map复习的更多相关文章

  1. iOS总结_UI层自我复习总结

    UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...

  2. vuex复习方案

    这次复习vuex,发现官方vuex2.0的文档写得太简略了,有些看不懂了.然后看了看1.0的文档,感觉很不错.那以后需要复习的话,还是先看1.0的文档吧.

  3. 我的操作系统复习——I/O控制和系统调用

    上篇博客介绍了存储器管理的相关知识——我的操作系统复习——存储器管理,本篇讲设备管理中的I/O控制方式和操作系统中的系统调用. 一.I/O控制方式 I/O就是输入输出,I/O设备指的是输入输出设备和存 ...

  4. 复习(1)【Maven】

    终于开始复习旧知识了,有输入必然要有输出.输入和输出之间的内化过程尤为重要,在复习的同时,真正把学到的东西积淀下来,加深理解. Maven项目概念与配置 Maven是一个项目管理和综合工具.Maven ...

  5. 《CSS权威指南》基础复习+查漏补缺

    前几天被朋友问到几个CSS问题,讲道理么,接触CSS是从大一开始的,也算有3年半了,总是觉得自己对css算是熟悉的了.然而还是被几个问题弄的"一脸懵逼"... 然后又是刚入职新公司 ...

  6. JS复习--更新结束

    js复习-01---03 一 JS简介 1,文档对象模型 2,浏览器对象模型 二 在HTML中使用JS 1,在html中使用<script></script>标签 2,引入外部 ...

  7. jQuery 复习

    jQuery 复习 基础知识 1, window.onload $(function(){});   $(document).ready(function(){}); 只执行函数体重的最后一个方法,事 ...

  8. jQuery5~7章笔记 和 1~3章的复习笔记

    JQery-05 对表单和表格的操作及其的应用 JQery-06 jQuery和ajax的应用 JQery-07 jQuery插件的使用和写法 JQery-01-03 复习 之前手写的笔记.实在懒得再 ...

  9. HTML和CSS的复习总结

    HTML(Hypertext Markup Language)超文本标记语言:其核心就是各种标记!<html> HTML页面中的所有内容,都在该标签之内:它主要含<head>和 ...

随机推荐

  1. “数据接口请求异常:error”,Layui-table使用遇到的最大一个坑

    后台返回的json格式必须和官方给的一模一样 code必须为0, code必须为0, code必须为0, code必须为0

  2. day5-2正则表达式

    正则表达式: 正则表达式对象的创建 1,构造函数 var pattern =new RegExp("正则表达式","修饰符") var pattern =new ...

  3. c++模板(翁恺c++公开课[34-35]学习笔记)

    为什么要有模板(templates):当我们需要一个列表(list),列表中元素可能都为X类型也可能都为Y类型,怎么来实现呢? 定义基类?可以实现,很多情况下可能不够简明的表达设计思想 克隆代码(写一 ...

  4. 记一次安装体验:pwn工具

    几天前删了JDK,结果和VM在一个目录中,结果VM全没了,重安走起 记载一下安装虚拟机出现的问题,官网一个字....慢,于是找了百度网盘,据说win10版本太低没法用,我就下了vw15.5.0(建立在 ...

  5. mybaits requestMap与requestType,以及对应的注解

    有的时候不喜欢用xml配置文件,但是xml配置文件的开发使用简单,自己经常要用到: 因为代码维护的缘故,有的时候看别人的代码,可能存在大量的mappper文件,也不是你想用注解就用注解的: 下面我还是 ...

  6. springmvc常用注解详解

    1.@Controller 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ...

  7. 执行SQL时出现: ORDER BY clause is not in GROUP BY clause and contains nonaggregated c

    注意: 采用navicat新建数据库时,需要将编码方式设置为,字符集:utf8 -- UTF-8 Unicode ,排序规则:utf8_general_ci 在运行sql语句时,出现以下问题: [Er ...

  8. IDEA工具java开发之 高级功能分屏是可以多次使用的 日志连接及浏览器 本地修改历 多列操作 查看方法调用情况

    ◆tabs分屏和独立 分屏是可以多次使用的  ◆日志连接及浏览器  ◆本地修改历史  ◆查看方法调用情况 ◆多列操作 可以同时删除也可以同时替换文字 Ctrl + shift + 右,选中一个词

  9. springcloud-zuul进阶篇

    一 前言 经过zuul初级篇(博客或者公主号springcloud专栏可以找到)的学习,读者都懂得如何简单的使用zuul进行路由网关配置,在进阶篇中你将获得zuul核心功能过滤器的基本使用,通过zuu ...

  10. UI的考核方式之【主题颜色 + 主题字体 + 主题样式】

    首先,项目中的颜色需要怎么管理呢? 宏?常量? 宏的值可以被改变,不用宏.那就用常量.那常量的名字怎么去起名呢? WSFConstants_Color_0xCCCCCC? WSFConstants_C ...