由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - How to sort a map in C++ STL based on Value, instead of Key
相关主题
C++ key/value 排序A programming interview question
Please help: sort XML with LinqVS 2005 shortcut keys don't work on windows 7
[合集] 用鼠标用的手痛咋办openssl dgst question
in what case you still want to use process instead of threa (转载)mutable keyed collection是什么意思?
[转载] KEY mapCassandra returns null row keys?
Keyboard binding for function keysAmazon S3 now supports server side encryption with customer-provided keys‏
Universal Hashing 是怎么回事?python一问,怎么实现这个函数
怎么把string变为一个variable的名字 ?VI用户们,你们写程序快么?
相关话题的讨论汇总
话题: value话题: sort话题: map话题: key话题: c++
进入Programming版参与讨论
1 (共1页)
i******e
发帖数: 171
1
map index_of_card; // ????
I want to sort the index (int) numerically. For example,
index_of_card.begin()->second will print out the samllest value,
index_of_card.end() ->second will print out the largest value, etc.
Thanks!
c****s
发帖数: 37
2
为什么不用
map

【在 i******e 的大作中提到】
: map index_of_card; // ????
: I want to sort the index (int) numerically. For example,
: index_of_card.begin()->second will print out the samllest value,
: index_of_card.end() ->second will print out the largest value, etc.
: Thanks!

i******e
发帖数: 171
3
I need map. For the time being, I have to use both
map and map.
I have thought map in C++ has the similiar way to be manipulated as
hash in Perl, where we can sort by key or by value.

【在 c****s 的大作中提到】
: 为什么不用
: map

p******f
发帖数: 162
4

you can sort c++ map by value if you want, but this would not be the
same sort carried out by the map container. I believe hash sort by
value in perl is the same case, ie. you just pass all the values to a
sort function.

【在 i******e 的大作中提到】
: I need map. For the time being, I have to use both
: map and map.
: I have thought map in C++ has the similiar way to be manipulated as
: hash in Perl, where we can sort by key or by value.

vi
发帖数: 309
5

I don't think this is doable without adding signaficant works.
You can't sort by value; and if you do, that's multi-key,
instead of key-value.

【在 i******e 的大作中提到】
: map index_of_card; // ????
: I want to sort the index (int) numerically. For example,
: index_of_card.begin()->second will print out the samllest value,
: index_of_card.end() ->second will print out the largest value, etc.
: Thanks!

i******e
发帖数: 171
6
oh, I feel good then. I have been afraid that I implemented sth which was al
ready there.

【在 vi 的大作中提到】
:
: I don't think this is doable without adding signaficant works.
: You can't sort by value; and if you do, that's multi-key,
: instead of key-value.

p******g
发帖数: 347
7
just pass a compare function or function object to sort,
your compare function(object) compares
the value instead of the key of your map.

【在 i******e 的大作中提到】
: map index_of_card; // ????
: I want to sort the index (int) numerically. For example,
: index_of_card.begin()->second will print out the samllest value,
: index_of_card.end() ->second will print out the largest value, etc.
: Thanks!

1 (共1页)
进入Programming版参与讨论
相关主题
VI用户们,你们写程序快么?[转载] KEY map
请教一个java的comparator的问题Keyboard binding for function keys
如何得到primary id呢?Universal Hashing 是怎么回事?
Client Side 怎么不让用户看到一些keys怎么把string变为一个variable的名字 ?
C++ key/value 排序A programming interview question
Please help: sort XML with LinqVS 2005 shortcut keys don't work on windows 7
[合集] 用鼠标用的手痛咋办openssl dgst question
in what case you still want to use process instead of threa (转载)mutable keyed collection是什么意思?
相关话题的讨论汇总
话题: value话题: sort话题: map话题: key话题: c++