1.

What are the differences between Vector and List in STL?

Answer»

Vectors and Lists are defined under C++ Standard Template Library (STL). These data structures are basically sequential containers implemented using STLs.

The differences between them are as follows:

  • A Vector is a contiguous BLOCK of memory locations similar to Arrays in “C” programming while a List stores non-contiguous blocks and uses a double LINKED list.
  • Inserting and DELETING elements in a List is easier compared to Vector as in the latter, shifting of elements is required and it is a tedious process.
  • However sorting and searching are much faster in Vector compared to List and in former no TRAVERSAL is required unlike List.
  • Lists support no numeric index LIKE Array while Vector supports the same.
    • Insertion and Deletion of elements in List has no iterator validation unlike Vector where the same is possible.


Discussion

No Comment Found