程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> C++ list

C++ list

編輯:C++入門知識

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)

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved