当前位置:编程学习 > C/C++ >>

C++ list

list将元素按顺序储存在链表中,与向量(vector)相比,它允许快速插入,删除,但是随机访问比较慢。

Member functions
(constructor)
Construct list (public member function)    //构造链表, list<int >  L;
(destructor)
List destructor (public member function)
operator=
Copy container content (public member function)   //可以实现链表间的赋值 list<int > a,b
  a=b;

Iterators:
begin
Return iterator to beginning (public member function)   //表头。   L.begin().  
end
Return iterator to end (public member function)            //表尾+1      L.end();
rbegin
Return reverse iterator to reverse beginning (public member function) //表尾 L.rbegin().
rend
Return reverse iterator to reverse end (public member function) //表头 L.rend();

Capacity:
empty
Test whether container is empty (public member function)    //判断链表是否为空,是空返回真,反之
size
Return size (public member function)             //返回链表大小
max_size
Return maximum size (public member function)  //返回链表的最大可取值
resize
Change size (public member function)          //重新调整链表大小

Element access:
front
Access first element (public member function)  //取表头
back
Access last element (public member function)   //取表尾

Modifiers:
assign
Assign new content to container (public member function)  //分配长度,和值
push_front
Insert element at beginning (public member function)        //在队头插入数据
pop_front
Delete first element (public member function)                    //弹出队头
push_back
Add element at the end (public member function)             //在队尾插入
pop_back
Delete last element (public member function)                   //弹出队尾元素
insert
Insert elements (public member function)                        //插入元素
erase
Erase elements (public member function)                         //删除元素
swap
Swap content (public member function)                           //交换不同链表的长度和取值
clear
Clear content (public member function)                          //清空链表

Operations:
splice
Move elements from list to list (public member function)    //实现链表见的合并
remove
Remove elements with specific value (public member function)  //移除指定元素 list.remove(20);//移除链表里值为20的
remove_if
Remove elements fulfilling condition (public member function template) //可以重载,移除指定范围的元素。bool single_digit (const int& value) { return (value<10); }
list.remove_if(single_digit);
unique
Remove duplicate values (member function)  //清除 链表里‘相同’的元素,这里的相同也可以实现重载。。如
 bool same_integral_part (double first, double second)
{ return ( int(first)==int(second) ); }
list.unique(same_integral_part);
merge
Merge sorted lists (public member function) //合并两个链表,如果两个链表有序,合成的链表也有序,如果没序,l1链表后接l2
sort
Sort elements in container (public member function)  //给聊表排序,同样可以重载。
reverse
Reverse the order of elements (public member function)  //将链表翻转

Allocator:
get_allocator
Get allocator (public member function)

 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,