C++ C#中的类向量

本文关键字:向量 C++ | 更新日期: 2023-09-27 18:31:54

C

#中C++ std::vector的类似类是什么?

我想要一个类,它将内部数组保留在内部,并支持O(1)在后面插入。

C++ C#中的类向量

这是一个列表,其中包含一些彼此大致等效(不是完全替换)的 C++/C# 容器:

  • std::vector -> List<T>

  • std::list -> LinkedList<T>

  • std::map -> SortedDictionary<Tkey, Tvalue>

  • std::set -> SortedSet<T>

  • std::unordered_set -> HashSet<T>

  • std::multiset -> SortedDictionary<Tkey, int>int 保持Tkey 秒数的计数)

  • std::unordered_map -> Dictionary<TKey, TValue>

  • std::list -> LinkedList ?
  • std::vector -> 列表 ?

std::list 由数组支持,每次删除都会产生内存复制,与 C# List 的行为相同。而 C# LinkedList 由 node list 支持,与 std::vector 相同。

所以我相信下面是正确的。

  • 标准::列表 ->
  • 列表
  • std::vector -> 链接列表