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. selenium webdriver 等待元素

    /**显示等待并返回元素 * @param driver * @param locator */ public static WebElement showWait(WebDriver driver, ...

  2. static的特性

    1,static方法就是没有this的方法.在static方法内部不能调用非静态方法,反过来是可以的.而且可以在没有创建任何对象的前提下,仅仅通过类本身来调用static方法.这实际上正是static ...

  3. Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)

    There are nn monsters standing in a row numbered from 11 to nn . The ii -th monster has hihi health ...

  4. python中numpy.concatenate()函数的使用

    numpy库数组拼接np.concatenate 原文:https://blog.csdn.net/zyl1042635242/article/details/43162031 思路:numpy提供了 ...

  5. ORACLE CPU过高的sql查询

    1. 根据占用CPU高的进程号来查询这个进程执行的SQL语句: CPU过高的进程号: #首先找到CPU过高的进程号 # top -bn1 是静态找到占用最高的进程   [root@localhost ...

  6. Golang mysql数据库

    基本操作: Open() – create a DB Close() - close the DB Query() - 查询 QueryRow() -查询行 Exec() -执行操作,update,i ...

  7. js加密(九)hr.bibibi md5

    1. 寻找加密js: 2. 结果: 3. execjs调用js即可.

  8. Spring之IOC、AOP和事务

    IOC 什么是IOC?如果你回答:Spring是个IOC容器,实现原理是反射,没了.这样证明你没有真正理解IOC. IOC的意思是控制反转,还有个外号叫依赖注入(DI).为什么起这么晦涩难懂的名字呢? ...

  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:块级按钮(拉伸至父元素100%的宽度)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Laradock 下安装Beast扩展

    laradock/php-fpm/Dockfile ########################################################################## ...