MAP--复杂map结构的构造
我的关键结构比如
struct{
int a;
int b;
int c;
}s;
因为这三个数据是基本信息,可以唯一区别一个设备。拿这样一个数据结构作为索引就能找到每个设备。
我现在想这么用
map<s, string>
因为map是二叉树,好像没法拿结构体比较大小,去索引,所以把结构体s改成类,重载小于号,让他能比较大小。
class s
{
public:
int a;
int b;
int c;
s(int m, int d, int u){a=m;b=d;c=u;}
bool operator < (const s &other)
{
if ((a<other.a) ||
((a==other.a)&&(b<other.b)) ||
((a==other.a)&&(b==other.b)&&(c<other.c)))
{
return true;
}
return false;
}
};
然后,
map<s, string> w;
s s1;
string s2;
一旦执行w.insert(make_pair(s1, s2));只要有这行就立刻报错。
要想使用一个类似结构体的数据结构作为KEY到底要怎么做呀?
是不是光重载一个小于号不够呀?
我现在好糊涂。有没有简单办法?
1.1
struct s {
int a;
int b;
int c;
bool operator<(const s&) const {
return true; }
};
map<s,string> m;
m.insert( make_pair(s(),"") );
1.2
struct s {
int a;
int b;
int c;
};
bool operator<(const s&,const s&) { return true; }
map<s,string> m;
m.insert( make_pair(s(),"") );
2.
struct s {
int a;
int b;
int c;
};
struct cmp {
bool operator()(const s&,const s&) const { return true; }
};
map<s,string,cmp> m;
m.insert(make_pair(s(),"" ) );
转载自:http://bbs.chinaunix.net/thread-1538318-1-1.html
MAP--复杂map结构的构造的更多相关文章
- STL——容器(Map & multimap)的拷贝构造与赋值
1. Map & multimap 的拷贝构造与赋值 map(const map &mp); //拷贝构造函数 map& operator=(con ...
- Map接口----Map中嵌套Map
package cn.good.com; import java.util.HashMap; import java.util.Iterator; import java.util.Map; impo ...
- 加锁的位置 (eq:map<key,map<>> 双集合 怎么 只加锁 在用到的对象位置,而不是把整个集合锁住)
比如上边的map里套map 定义变量为data,例如组队副本 npc 为1 下有众多房间 即Map<1,<roomId,room>> ,处于多线程下,一个线程在 npc为1的下 ...
- 2019/2/20训练日记+map/multi map浅谈
Most crossword puzzle fans are used to anagrams - groups of words with the same letters in different ...
- LinkedHashSet、Map、Map接口HashMap、Hashtable,TreeSet、TreeMap、如何选择使用集合实现类,Collections工具类
一.Set接口实现类LinkedHashSet 实现继承图: 1.LinkedHashSet的全面说明 1) LinkedHashSet是 HashSet的子类 2) LinkedHashSet底层是 ...
- Map生成器 map适配器如今能够使用各种不同的Generator,iterator和常量值的组合来填充Map初始化对象
Map生成器 map适配器如今能够使用各种不同的Generator,iterator和常量值的组合来填充Map初始化对象 package org.rui.collection2.map; /** * ...
- java中遍历MAP,嵌套map的几种方法
java中遍历MAP的几种方法 Map<String,String> map=new HashMap<String,String>(); map.put("us ...
- arm-none-eabi-g++ -Xlinker -T "../LF3Kmonitor.ld" -Xlinker -Map="Bogota_ICT_V.map"-ram-hosted.ld -mc
1.arm-none-eabi-g++:是编译ARM裸板用的编译器,不依赖于操作系统. 2.-Xlinker -T "../LF3Kmonitor.ld" -Xlinker -Ma ...
- 03-封装BeanUtil工具类(javabean转map和map转javabean对象)
package com.oa.test; import java.beans.BeanInfo; import java.beans.IntrospectionException; import ja ...
- map泛型 map不指定泛型 与 Map<Object,Object>的区别
map泛型 map不指定泛型 与 Map<Object,Object>的区别 private void viewDetail(){ Map map1 = new HashMap(); Ma ...
随机推荐
- 获取Excel数据(或部分数据)并导出成txt文本格式
运行代码前先导入jxl架包,以下代码仅供参考: 测试excel文件(我要获取该excel的内容为省.县.乡.村.组和PH的值): ExcelTest01类代码如下: // 读取Excel的类 impo ...
- 解决编译时出现的警告:format string is not a string literal (potentially insecure)
NSLog([NSString stringWithFormat:@"%@/%@B.jpg", createDir, uuid]);//这是我的写法 应该写成 NSString * ...
- UIView的layoutSubviews,initWithFrame,initWithCoder方法
****************************layoutSubviews************************************ layoutSubviews是UIView ...
- IE 和 FF 写不同的CSS
.FireFox 下如何使连续长字段自动换行 众所周知IE中直接使用word-wrap:break-word 就可以了, FF中我们使用JS插入的技巧来解决 <style type=" ...
- 2015年5月9日 student information management system
/*大作业SIMS*///头文件 #ifndef __FUNC_C__ #define __FUNC_C__ #include <stdio.h> #include <stdlib. ...
- java中list的使用方法
LIST是个容器接口,可以理解为动态数组,传统数组必须定义好数组的个数才可以使用,而容器对象无须定义好数组下标总数, 用add()方法即可添加新的成员对象,他可以添加的仅仅只能为对象,不能添加基本数据 ...
- Java NIO的探究
1.Java NIO与阻塞IO的区别 阻塞IO通信模型(在上一篇<J2SE网络编程之 TCP与UDP>博客中有所介绍) 我们知道阻塞I/O在调用InputStream.read()方法时是 ...
- 修改TabPageIndicator下划线的颜色
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator"> < ...
- asp.net C# 题目大全
net001在线饰品销售系统 net002鲜花商城 net003商品销售管理系统 net004在线辅导答疑 net005土地税务管理系统 net006旅游管理 net007房产中介 net008房产信 ...
- hdu_5145_NPY and girls(莫队算法+组合)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5145 题意:给你n,m,共有n个女孩,标号为1—n,n个数xi表示第ith个女孩在第xi个教室,然后下 ...