[英]C++ STL Vector of lists inserting elements at the end of the lists
I got a series of numbers and I need to make a vector of lists std::vector<std::list<int>> v
. 我得到了一系列数字,我需要制作一个列表
std::vector<std::list<int>> v
。 I will give an example because it's easier to explain. 我将举一个例子,因为它更容易解释。 Example:
例:
Series of numbers: 5 7 2 0 3 9 10 4
数字系列:
5 7 2 0 3 9 10 4
Vector after parsing the numbers: v[0] = {5, 0}; v[1] = {2, 10, 4}; v[2] = {7, 3}; v[3] = {9}
解析数字后的向量:
v[0] = {5, 0}; v[1] = {2, 10, 4}; v[2] = {7, 3}; v[3] = {9}
v[0] = {5, 0}; v[1] = {2, 10, 4}; v[2] = {7, 3}; v[3] = {9}
v[0] = {5, 0}; v[1] = {2, 10, 4}; v[2] = {7, 3}; v[3] = {9}
And {2, 10, 4}
is a list. v[0] = {5, 0}; v[1] = {2, 10, 4}; v[2] = {7, 3}; v[3] = {9}
并且{2, 10, 4}
是一个列表。
I want to parse the series of numbers once and put the numbers directly in the vector at the end of the list. 我想解析一系列数字,然后将数字直接放在列表末尾的向量中。 For this example, put 5 in
v[0]
, then put 7 in v[2]
, then put 2 in v[1]
, then put 0 at the end of the list in v[0]
after 5... 对于此示例,在
v[0]
放入5,然后在v[2]
放入7,然后在v[1]
放入2,然后在5之后的v[0]
中将列表的末尾放入0 ...
I want to know only how to insert an element in a vector on a specific position at the end of the list that is on that specific position.
我只想知道如何在向量中的特定位置的列表末尾的特定位置插入元素。
to append val
to the list at position i
, you would: 将
val
附加到位置i
的列表中,您将:
v[i].push_back(val);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.