且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从集合中删除特定元素

更新时间:2023-01-17 18:41:34

您可以使用STL中的设置模板。

http://www.cplusplus.com/reference/set/set/ [ ^ ]

You may us the set template in STL.
http://www.cplusplus.com/reference/set/set/[^]
Modifiers:
insert
Insert element (public member function)
erase
Erase elements (public member function)



有一些示例代码:

http://www.cplusplus.com/reference/set/set/erase/ [ ^ ]


您可以从近乎删除一个随机元素所有容器类,但不是来自队列或堆栈。它可能是列表,矢量,地图等。我没有计算本机C / C ++数组,它不是容器类。你应该选择哪种容器类?这取决于您的其他要求。



-SA
You can remove a random element from nearly all container classes, but not from a queue or a stack. It could be list, vector, map, etc. I did not count native C/C++ array, which is not a container class. What container class should you choose? It depends on your other requirements.

—SA