I need some sort of dynamic array in C++ where each element have their own id represented by an int.
The datatype needs these functions:
- int Insert() – return ID
- Delete(int ID)
- Get(ID) – return Element
What datatype should I use? I’we looked at Vector and List, but can’t seem to find any sort of ID. Also I’we looked at map and hastable, these may be usefull. I’m however not sure what to chose.
A
std::mapcould work for you, which allows to associate a key to a value. The key would be your ID, but you should provide it yourself when adding an element to the map.An hash table is a sort of basic mechanism that can be used to implement an unordered map. It corresponds to std::unordered_map.