C++ List is the inbuilt sequence containers that allow non-contiguous memory allocation. The list doesn’t provide fast random access, and it only supports sequential access in both directions. The list is a sequence container available with STL(Standard Template Library) in C++. By default, the list is a doubly-linked list. Since it is a doubly-linked list, the insertion and deletion are fast on the list.

It uses non-contiguous memory allocation, so traversal is slow compared to  vector in C++.

C++ List Example

The list allows insertion and deletion operation anywhere within a sequence in constant time.

Elements of the list can be scattered in the different chunks of memory. Container stores the necessary information to allow sequential access to its data.

C++ Lists can shrink or expand as needed from both ends at run time. The storage requirement is fulfilled automatically by the internal allocator.

Zero-sized lists are also valid. In that case list.begin() and list.end() points to the same location. But the behavior of calling front() or back() is undefined.

#c++ #c++ list

C++ List Example | List in C++ Standard Template Library
2.00 GEEK