📅  最后修改于: 2020-10-17 07:42:56             🧑  作者: Mango
#include
#include
using namespace std;
int main()
{
list l;
}
它创建一个空的整数类型值列表。
列表也可以使用参数初始化。
#include
#include
using namespace std;
int main()
{
list l{1,2,3,4};
}
列表可以通过两种方式初始化。
list new_list{1,2,3,4};
or
list new_list = {1,2,3,4};
以下是列表的成员函数:
Method | Description |
---|---|
insert() | It inserts the new element before the position pointed by the iterator. |
push_back() | It adds a new element at the end of the vector. |
push_front() | It adds a new element to the front. |
pop_back() | It deletes the last element. |
pop_front() | It deletes the first element. |
empty() | It checks whether the list is empty or not. |
size() | It finds the number of elements present in the list. |
max_size() | It finds the maximum size of the list. |
front() | It returns the first element of the list. |
back() | It returns the last element of the list. |
swap() | It swaps two list when the type of both the list are same. |
reverse() | It reverses the elements of the list. |
sort() | It sorts the elements of the list in an increasing order. |
merge() | It merges the two sorted list. |
splice() | It inserts a new list into the invoking list. |
unique() | It removes all the duplicate elements from the list. |
resize() | It changes the size of the list container. |
assign() | It assigns a new element to the list container. |
emplace() | It inserts a new element at a specified position. |
emplace_back() | It inserts a new element at the end of the vector. |
emplace_front() | It inserts a new element at the beginning of the list. |