C ++ std :: function of the difference contrast difference and its member list and std :: forward_list of

The main difference:

list is a doubly linked list, forward_list is doubly linked list.

 

Member function of the difference:

Function name list forward_list
back() has no
size() has no
insert() has no
emplace() has no
erase() has no
push_back() has no
emplace_back() has no
splice() has no
     
before_begin() no has
cbefore_begin() no has
insert_after() no has
emplace_after() no has
erase_after() no has
splice_after() no has
     

 

 

 

* Forward_list xxx_after in a series of design () reasons:

Wherein the back element knows only the elements, and do not know the previous element. (Characteristic way linked list) so this operation is similar to insert, before the need to specify an iterator element, and then insert, can connect the entire list.

https://www.cnblogs.com/wuchanming/p/3915567.html

Test code:

#include <the iostream> 
#include <String> 
#include <List> 
#include <forward_list> 

the using namespace STD; 

int main () 
{ 
	
	List <int> lis5 = {l, 2,3}; 
	forward_list <int> = {flis5 1,2,3}; 

	/////////////////////////////////////////// /////////////////////////////// 
	
	lis5.insert (lis5.begin (), 44 is); // 2. 3. 1 44 is , the equivalent of "insert_before", but does not have this function. 
	flis5.insert_after (flis5.begin (), 44 is); // 2. 3. 1 44 is 

}

  

 

Guess you like

Origin www.cnblogs.com/alexYuin/p/12076306.html