0

Container

what is the difference between std list and vector ?

30th Aug 2018, 7:26 PM
Joel Karn
2 odpowiedzi
+ 3
Joel Karn difference between them is that memory location for elements of vector is contiguous like array... while for list, it's non contiguous... As elements are next to each other in vector, you can iterator through same easily...Random access of element is possible due to this...where as in list to go to fifth element, for example, you have to start from first and then one by one reach to fifth... As vector is having contiguous location, one element insertion or deletion in between cost all element to shift or relocate to new location.... this is less costly operation in list as only two pointers pointing to in between locations need to be updated in case of additional or remove of element
1st Sep 2018, 5:43 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
thanks a lot.
1st Sep 2018, 5:48 AM
Joel Karn