A. what are list?
Lists are containers for sequences that belong to the class of class templates. They are also employed for linear information storage. A list can only include elements of the same data type. Comparing lists to other containers like arrays and vectors, we can insert and remove elements more quickly with lists. Although it takes a little longer to access pieces in a random position.
B. What speeds up adding to and removing from a list?
An array keeps the elements in a continuous fashion, making it time-consuming to insert one element because doing so requires shifting other items. However, we can easily change the address that the pointer points to in a list.
list<data_type> list_name;
Any data type could be used in place of data type. Lists provide bidirectional communication and offer an effective method for insertion and deletion operations, which is one advantage of using lists. A list’s elements can be accessed and used via a variety of methods, the first of which is the push back method. Visit this website, std::list, to access all the methods and member functions in detail.
C.Initializing a list
Similar to how we initialised a vector, a list could also be initialised in this manner. When a list is defined, all of its elements may be added to it as initial elements.
list<int> l = {1, 2, 3, 4};
Alternately, it might even be initialised with components to be added as a parameter.
list<int> l{1, 2, 3, 4};