No, the properties of the deque are similar to that of the vector when it comes to insertion, which is a constant-time activity for elements added at the end of sequence and a linear-time activity for elements inserted in the middle. However, the vector allows insertion at only one end (the bottom), whereas the deque allows for insertion at both ends (the top and the bottom).
The STL list class is bound to respect the property that iterators pointing to elements in the list should remain valid irrespective of the position of the elements in the list itself. Although STL algorithms work on list too, the list’s member functions ensure that the aforementioned property of the list is withheld and iterators pointing to elements in the list before the sort was done continue to point to the same elements even after the sort.
You must provide the default comparison operator == and the default < operator to any class that can be used in STL containers.
list<int> linkInts(10); // list of 10 integers
auto firstElement = linkInts.begin();
You would replace auto by the following explicit type declaration:
list<int> linkInts(10); // list of 10 integers
list<int>::iterator firstElement = linkInts.begin();
Elements can be inserted in the middle of the list as they can be at either end. There is no gain or loss in performance due to position.
The specialty of the list is that operations such as these don’t invalidate existing iterators.
Yes, an overloaded version of the insert() function enables you to insert a range from a source collection.
set <int> is a set of integers. This takes the default sort predicate std::less <T> to sort items in order of ascending magnitude and can also be expressed as set <int, less <int>>. To sort in order of descending magnitude, define the set as set <int, greater <int>>.
A set is not meant to be used to contain non-unique values. The set of strings would contain only one instance of "Jack".
No. Some STL implementations might allow the user to change the value of an element inside a set via an iterator returned by, for example, find. However, this is not the correct thing to do. An iterator to an element in the set should be used as a const iterator—even when the STL implementation has not enforced it as such.