显示未排序的STL std :: set的内容 [英] Displaying contents of STL std::set unsorted

查看:114
本文介绍了显示未排序的STL std :: set的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

STL std::set不会按输入顺序存储元素,而是存储已排序的元素.任何人都可以提出任何建议来显示未排序集合的内容的任何想法(按输入顺序).

谢谢.

Hi all,

a STL std::set does not store the elements in the same sequence as it is input, rather it stores the elements sorted. Can anyone suggest any idea of displaying the contents of the set unsorted (in the input sequence).

Thank you.

推荐答案

看看Boost.MultiIndex [ ^ ]库.


您需要一个辅助容器(包含所有注意事项).
:)
You need an auxiliary container (with all the caveats of the case).
:)


如果您想存储一堆未排序的元素,我可以谦虚地建议使用std::vector (如果您大致知道要添加多少个元素)或std::list?它们都提供了push_back函数,可以为您保留插入顺序.

[哦,如果这就是为什么您首先使用std::set 的原因,那么您还必须找到其他检查唯一性的方法.]

干杯,

If you want to store a bunch of elements unsorted may I humbly recommend using either std::vector (if you know roughly how many elements you''re going to add) or std::list? Both of them provide a push_back function that''ll preserve the insertion order for you.

[Oh, and you''ll have to find some other way of checking for uniqueness as well if that was why you were using std::set in the first place.]

Cheers,

Ash


这篇关于显示未排序的STL std :: set的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆