如何在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