【问题标题】:Is there any data structure or library in C++ can work like Python List and DictionaryC++ 中是否有任何数据结构或库可以像 Python List 和 Dictionary 一样工作
【发布时间】:2013-04-30 16:18:39
【问题描述】:

C++中是否有任何数据结构或库可以像Python List和Dictionary一样工作?

谢谢

【问题讨论】:

  • @JoranBeasley -- 我不会说一个列表-> 链接列表。例如,列表对象是可索引的。它们更像是动态数组(但就这些而言,我不知道 C++ 有什么)。
  • @JoranBeasley Python 的list 一个动态数组。它(基本上)与std::vector 的数据结构相同,与std::list 完全不同。
  • @delnan -- 是的...有一些操作可以让它们更好地使用(例如removeinsert ...)

标签: c++ python list dictionary


【解决方案1】:
  • Python 的list

    标准std::vector<> 可能是您需要的。但是,与 Python 的 list 不同,标准 C++ 容器不是异构的std::vector<T> 将专门存储 T 实例。您可以通过使用boost::anyboost::variant 或多态来实现类似的行为,具体取决于用例。

  • Python 的dict

    对于字典,您可以查看 std::map<>,或者更准确地说是 boost::unordered_map,因为 map 实际上是一棵红黑树。

【讨论】:

    猜你喜欢
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多