简体   繁体   中英

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

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM