阅读程序(4)
来源:互联网 发布:淘宝快递盒上会有 编辑:程序博客网 时间:2024/05/21 10:27
*All right reserved.
*文件名称:test.cpp
*作 者:韩双志
*完成日期:2016年6月20日
*版本号:v1.0
*
*问题描述:理解map
*输入描述:
*输出描述:
/*
#include <algorithm>
#include<map>
#include<iterator>
#include<iostream>
#include<cstring>
using namespace std;
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
int main()
{
map<const char*, int, ltstr> months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;
cout << "june -> " << months["june"] << endl;
map<const char*, int, ltstr>::iterator cur = months.find("june");
map<const char*, int, ltstr>::iterator prev = cur;
map<const char*, int, ltstr>::iterator next = cur;
++next;
--prev;
cout << "Previous (in alphabetical order) is " << (*prev).first << endl;
cout << "Next (in alphabetical order) is " << (*next).first << endl;
return 0;
}
*/
运行结果
知识点总结
Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,
学习心得
要好好学习
- 阅读程序(4)
- 阅读程序(4)
- 阅读程序(4)
- 阅读程序(3)(4)
- 第三周:程序阅读(4)
- 第三周阅读程序 (4)
- 第四周 阅读程序(4)
- 第四周阅读程序 (4)
- 第五周程序阅读(4)
- 第四周程序阅读(4)
- 第五周 阅读程序(4)
- 第五周 阅读程序 (4)
- 第六周 阅读程序(4)
- 第六周阅读程序 (4)
- 第六周 阅读程序 (4)
- 第八周程序阅读(4)
- 第八周 阅读程序 (4)
- 第十一周阅读程序(4)
- js 实现dom的控制
- MAC系统上设置华为手机的调试模式
- JavaScript---网络编程(10)--DHTML技术演示(3)-多选框
- ios 学习之 NSPredicate 模糊、精确、查询
- 更新百度地图,极光推送SDK 时无效
- 阅读程序(4)
- Python模块学习——logging
- Mysql错误: ERROR 1205: Lock wait timeout exceeded解决办法
- VRRP协议详解-----(1)
- jpeg 与 png 图片格式的区别
- javassist的理解
- YII2.0如何将分页功能 ?page=* 修改为 /page/*.html
- Bootstrap 教程第四课:制作一组功能图标按钮
- 训练4 习题4