Lists are sequence containers that allow non-contiguous memory allocation. As compared to vector, list has slow traversal, but once a position has been found, insertion and deletion are quick. Normally, when we say a List, we talk about doubly linked list. For implementing a singly linked list, we use forward list.
A list can be created with the help of constructor in C++. The syntax to do it is:
list<type> list_name(size_of_list, value_to_be_inserted);
Below programs show how to create a List with Constructor in C++.
100 100 100 100 100 100 100 100 100 100
Geeks Geeks Geeks Geeks Geeks
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Does C++ compiler create default constructor when we write our own?
- Can a constructor be private in C++ ?
- Copy Constructor in C++
- Constructor Overloading in C++
- Constructor Delegation in C++
- What is conversion constructor in C++?
- Passing a vector to constructor in C++
- When should we write our own copy constructor?
- Dynamic Constructor in C++ with Examples
- Advanced C++ | Virtual Constructor
- Difference Between Constructor and Destructor in C++
- When is copy constructor called?
- Is it possible to call constructor and destructor explicitly?
- Why copy constructor argument should be const in C++?
- Is body of a Default Constructor blank in C++?
- Order of Constructor/ Destructor Call in C++
- Advanced C++ | Virtual Copy Constructor
- Copy constructor vs assignment operator in C++
- C++ default constructor | Built-in types
- Calling virtual methods in constructor/destructor in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.