Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

push back for the map container

we got this map :

std::map <int, int> values;

would this function be the same as the push_back function of a Vector :

void PushBack(int value)
{
  values[values.size()] = value;
}

since size returns the size of the container I thought it would be correct, according to the following scenario it is : index 0 = 200 index 1 = 150 you want to push back 100, values.size() would return 2, right? so then, it would , just like the normal push_back go inside index 2, correct?

like image 693
user2140285 Avatar asked Oct 21 '25 05:10

user2140285


1 Answers

The whole point of maps is to lookup and store data based on a key that uniquely represents that data.

If you're doing this there's no point in using a map; you should choose another data structure that more appropriately addresses the design needs of the application.

like image 97
John Humphreys Avatar answered Oct 23 '25 20:10

John Humphreys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!