如何在C++ STL中使用构造函数创建List
在本教程中,我们将讨论一个程序,了解如何使用C++ STL中的构造函数创建List。
List是用于以非连续方式在内存中存储元素的数据结构。与矢量相比,插入和删除是十分快速的。
范例
#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;
}输出
100 100 100 100 100 100 100 100 100 100
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C编程
C++
C#
MongoDB
MySQL
Javascript
PHP