通用类型 vc++_C ++中的对象列表的标准或通用数据结构是什么?

通用类型 vc++

In C++, what’s the standard or common data structure for a list of objects?

在C ++中,对象列表的标准或通用数据结构是什么?

In C++, the common data structure for a sequence (“list”) of objects may be std::vector.

C ++中 ,对象序列(“列表”)的通用数据结构可以是std :: vector

A vector is a dynamically resizable array. It is “The most extensively used container in the C++ Standard Library …, offering a combination of dynamic memory management and efficient random access.” — Lock-free Dynamically Resizable Arrays

向量是可动态调整大小的数组。 它是“ C ++标准库中使用最广泛的容器……,它结合了动态内存管理和有效的随机访问功能。” —无锁动态可调整大小的阵列

And vector is the default first data structure you should think about for a problem for its compactness and efficiency. Bjarne Stroupstrup has an excellent talk on this, check it out.

vector是您要考虑的紧凑性和效率问题的默认第一个数据结构。 Bjarne Stroupstrup在这方面有出色的演讲, 请查看

From the standard draft C++11 (with important parts highlighted):

标准C ++ 11草案中 (突出显示了重要部分):

A vector is a sequence container that supports random access iterators. In addition, it supports (amortized) constant time insert and erase operations at the end; insert and erase in the middle take linear time. Storage management is handled automatically, though hints can be given to improve efficiency. The elements of a vector are stored contiguously

向量是支持随机访问迭代器的序列容器。 此外,它在末尾支持(摊销)恒定时间插入和擦除操作在中间插入和擦除需要线性时间存储管理是自动处理的 ,尽管可以提供一些提示以提高效率。 向量的元素是连续存储的 ……

Check the standard draft section 23.3.6 for more details.

有关更多详细信息,请参见标准草案第23.3.6节。

One usage example from cppreference.com:

来自cppreference.com的一个用法示例:

#include <iostream>
#include <vector>
 
int main()
{
    // Create a vector containing integers
    std::vector<int> v = {7, 5, 16, 8};
 
    // Add two more integers to vector
    v.push_back(25);
    v.push_back(13);
 
    // Iterate andprint values of vector
    for(int n : v) {
        std::cout << n << 'n';
    }
}

Run it on Caliru.

在Caliru上运行它。

Answered by dtivl.
dtivl回答。

翻译自: https://www.systutorials.com/whats-the-standard-or-common-data-structure-for-a-list-of-objects-in-c/

通用类型 vc++

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值