Forward_list
Forward_list is only available in the c++11 version. Forward_list is implemented as a single-linked list, and list is a doubly linked list, so forward_list is more efficient than list. Forward_list design is the pursuit of efficiency, and we write the C format of the single linked list as efficient.
Forward_list does not have a size member function, given the efficiency issue. Since it is essentially a linked list, there is a size member that consumes constant time to count its sizes. This will require some extra space and will reduce the efficiency of the INSERT and delete operations. If you want to get the size of the forward_list , you can invoke the distance algorithm operation on begin and end.
forward_list Most of the operations are similar to the list, here is a simple look at a few different operations:
Iterators:
List is a doubly linked list, so there is a reverse iterator, and forward_list does not have a reverse iterator. But there are two more iterators than list:
Iterator Before_begin () noexcept;
Const_iterator before_begin () const noexcept;
Const_iterator cbefore_begin () const noexcept;
These two iterators point to the position before the first element, so they cannot be dereferenced. It can be used as Emplace_after, Insert_after, erase_after or Splice_after parameters.
To add an action to delete an element:
Template <class ... args> void Emplace_front (Args&& .... Args);
A node is inserted in front of the node of the list head, and the new node is constructed with args.
void Push_front (const value_type& val);
void Push_front (value_type&& val);
A node is inserted in front of the node of the list head, but unlike Emplace_front, the new node is copied or transferred by Val.
Template <class ... Args> iterator Emplace_after (const_iterator position, args&& .... Args);
Iterator Insert_after (const_iterator position, const value_type& val);
Iterator Insert_after (const_iterator position, value_type&& val);
Iterator Insert_after (const_iterator position, Size_type N, const value_type& val);
Template <class inputiterator> iterator insert_after (const_iterator position, Inputiterator first, Inputiterator last);
Iterator Insert_after (const_iterator position, initializer_list<value_type> il);
Inserting a new node after position
Iterator Erase_after (const_iterator position, const_iterator last);
Remove a node from a position location
void Pop_front ();
Delete First node
Because forward_list is a single-linked list, in order to be able to function with the list, it is necessary to before_begin the iterator so that the new node can be inserted before the head node.
The rest of the functions are similar to the list, which is not repeated here. The thing to remember is that forward_list does not have a size member function. You need to calculate it yourself to get its size.
Qlinkedlist
Qlinkedlist is the true link list of Qt. Qlinkedlist is actually the same as std::list, and is also a doubly linked list. Qlist the actual internal or an array of pointers. The functions provided by Qlinkedlist are mostly the same as those of qlist, so let's look at a few different places.
int qlinkedlist::size () const
Returns the size of the list, that is, the number of nodes. and forward_list does not have this function.
Const_iterator Qlist::constbegin () const
Const_iterator qlist::constend () const
This is an iterator that qlist returns to STL style. Qlinkedlist does not provide such a function.
void Qlist::append (const T & value)
void Qlist::append (const qlist<t> & value)
void Qlinkedlist::append (const T & value)
Qlinkedlist does not accept the APPEND function of a qlinkedlist parameter.
The most important difference is:
Qlinkedlist No T & |
operator[] (int i) |
Linked lists are definitely not supported for index operations.
So all index-based operations provided by Qlist, Qlinkedlist are not supported, such as:
Const T & |
at (int i) const |
void |
Insert (int i, const T & value) |
void |
Move (int from, int to) |
void |
replace (int i, const T & value) |
T |
takeat (int i) |
void |
Swap (int i, int j) |
There may be other functions, which are not listed here.
The qlinkedlist provides a conversion function with Std::list:
Qlinkedlist<t> |
Fromstdlist (const std::list<t> & list) |
Std::list<t>qlinkedlist::tostdlist () const
One thing to keep in mind: The QT container is implicitly shared. Qlinkedlist Nature also supports implicit sharing.
http://blog.csdn.net/hai200501019/article/details/11787097
Qlinkedlist and Std::forward_list (both doubly linked lists, do not support operator[], the advantage may be that both insert and delete are relatively fast)