e****s 发帖数: 46 | 1 我如果用std::map存放一些字符串,发现里面的字符串并没有排序
如果用std::map存放一些字符,发现字符是排序的,请问哪位大侠给解释一
下为什么 | s******o 发帖数: 2233 | 2 in the first case, it's ranked by pointer addresses...
【在 e****s 的大作中提到】 : 我如果用std::map存放一些字符串,发现里面的字符串并没有排序 : 如果用std::map存放一些字符,发现字符是排序的,请问哪位大侠给解释一 : 下为什么
| L*******s 发帖数: 63 | 3 Cause C-Style strings (char*) are not compared by < or >.
Use std::string or any string classes that have those operator overloaded.
【在 e****s 的大作中提到】 : 我如果用std::map存放一些字符串,发现里面的字符串并没有排序 : 如果用std::map存放一些字符,发现字符是排序的,请问哪位大侠给解释一 : 下为什么
| t*****n 发帖数: 4908 | 4 http://www.sgi.com/tech/stl/SortedAssociativeContainer.html
A Sorted Associative Container is a type of Associative Container. Sorted
Associative Containers use an ordering relation on their keys; two keys are
considered to be equivalent if neither one is less than the other. (If the
ordering relation is case-insensitive string comparison, for example, then
the keys "abcde" and "aBcDe" are equivalent.)
Sorted Associative Containers guarantee that the complexity for most
operations is never worse than logarithmic [1], and they also guarantee that
their elements are always sorted in ascending order by key.
[1] This is a much stronger guarantee than the one provided by Associative
Container. The guarantees in Associative Container only apply to average
complexity; worst case complexity is allowed to be greater. Sorted
Associative Container, however, provides an upper limit on worst case
complexity. |
|