Consider a scenario where you have a large dataset and you need to frequently erase and insert elements in the middle of the data. Which STL container should be avoided in order to prevent frequent reallocations and data movements? 

  • vector 
  • list 
  • deque 
  • set
The STL vector maintains its elements in a contiguous block of memory. Inserting or erasing elements in the middle requires shifting elements, which can be expensive, especially for large datasets. This might cause frequent reallocations and data movements, impacting performance.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *