通用类型 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上运行它。
翻译自: https://www.systutorials.com/whats-the-standard-or-common-data-structure-for-a-list-of-objects-in-c/
通用类型 vc++
在C++中,std::vector是最常用的数据结构,用于存储对象列表。它提供了动态内存管理和高效的随机访问,是解决紧凑性和效率问题的首选。向量支持随机访问迭代器,且在末尾插入和删除操作的时间复杂度为常数。

8653

被折叠的 条评论
为什么被折叠?



