
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a List with Constructor in C++ STL
In this tutorial, we will be discussing a program to understand how to create a List with constructor in C++ STL.
List are data structures to store elements in memory in a non-contiguous fashion. They are insertion and deletion quick as compared to vectors.
Example
#include <iostream> #include <list> using namespace std; //printing the list void print_list(list<int> mylist){ list<int>::iterator it; //printing all the elements for (it = mylist.begin(); it != mylist.end(); ++it) cout << ' ' << *it; cout << '\n'; } int main(){ //creating list with help of constructor list<int> myList(10, 100); print_list(myList); return 0; }
Output
100 100 100 100 100 100 100 100 100 100
Advertisements