c++ 中的类似集合的数据结构是什么?
我需要利用delphi集合的优点,例如c++中的“in”,但我不知道c++中是否有像集合这样的数据结构
我知道我可以使用数组代替,但正如我所说的我想使用像“in”这样的集合优势,那么c++中是否有像集合这样的内置数据结构?
如果是,请解释如何使用它,我仍然是 c++ 的初学者。
如果不是,有什么方法可以表示它(除了数组,因为我知道)。
提前致谢 :)
I need to use the advantages of delphi sets like "in" in c++, but I don't know if there is a data structure like sets in c++
I know that I may use an array instead, but as I have said I want to use sets advantages like "in", so is there any built in data structure like sets in c++?
If yes, please explain how to use it, I'm still a starter in c++
If no, is there any way to represent it (exept array since I know it).
thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有一个名为
std::set
的标准库容器...我不知道 delphi,但是可以使用实现一个简单的 element in set 操作>find
方法并将结果与end
进行比较:其他操作可能会实现为标准库中的算法(
std::union
、std: :差异
...)There is a standard library container called
std::set
... I don't know delphi, but a simple element in set operation would be implemented by using thefind
method and comparing the result withend
:Other operations might be implemented as algorithms in the standard library (
std::union
,std::difference
... )使用
std::set
。请参阅 http://www.cplusplus.com 以供参考。Use
std::set
. See http://www.cplusplus.com for reference.在 C++ 中没有类似的集成。根据您的需要,您可能需要使用位标志和按位运算或 std::bitset 标准容器(当然,除了 std::set 之外)。如果您使用 C++Builder,还有一个模拟 Delphi 集的类 - 在 System.hpp 中搜索 BaseSet 或 SetBase 或类似的内容 - 我不记得确切的名称。
In C++ there is nothing similarly integrated. Depending on your needs you might want to use bit flags and bitwise operations or the std::bitset standard container (besides std::set, of course). If you are using C++Builder there is also a class that simulates Delphi sets - search System.hpp for something like BaseSet or SetBase or similar - I don't recall the exact name.
是的,第 12 页描述了一个 C++ STL
set
容器类。 Stroustrup 的 TC++PL(特别版)第 491 节。Yes, there is a C++ STL
set
container class described on p. 491 of Stroustrup's TC++PL (Special Ed.).STL算法有以下特点
来自 MSDN
set_difference
将属于一个已排序源范围但不属于第二已排序源范围的所有元素合并为单个已排序目标范围,其中排序标准可由二元谓词指定。
设置交集
将属于两个排序源范围的所有元素联合到单个排序目标范围中,其中排序标准可以由二元谓词指定。
设置对称差异
将属于一个(但不是两个)已排序源范围的所有元素合并到单个已排序目标范围中,其中排序标准可以由二元谓词指定。
set_union
将属于两个排序的源范围中的至少一个的所有元素联合到单个排序的目标范围中,其中排序标准可以由二元谓词指定。
STL algorithm has the following
From MSDN
set_difference
Unites all of the elements that belong to one sorted source range, but not to a second sorted source range, into a single, sorted destination range, where the ordering criterion may be specified by a binary predicate.
set_intersection
Unites all of the elements that belong to both sorted source ranges into a single, sorted destination range, where the ordering criterion may be specified by a binary predicate.
set_symmetric_difference
Unites all of the elements that belong to one, but not both, of the sorted source ranges into a single, sorted destination range, where the ordering criterion may be specified by a binary predicate.
set_union
Unites all of the elements that belong to at least one of two sorted source ranges into a single, sorted destination range, where the ordering criterion may be specified by a binary predicate.