Ovidiu Firescu
Ovidiu Firescu

Reputation: 405

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. I will give an example because it's easier to explain. Example:

Series of numbers: 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} And {2, 10, 4} is a list.

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...

Upvotes: 0

Views: 601

Answers (1)

Marshall Clow
Marshall Clow

Reputation: 16670

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:

v[i].push_back(val);

Upvotes: 3

Related Questions