The QLinkedList class is a template class that provides linked lists. 更多...
| 頭: | #include <QLinkedList> |
| qmake: | QT += core |
注意: 此類的所有函數 可重入 .
| class | const_iterator |
| class | iterator |
| typedef | ConstIterator |
| typedef | Iterator |
| typedef | const_pointer |
| typedef | const_reference |
| typedef | const_reverse_iterator |
| typedef | difference_type |
| typedef | pointer |
| typedef | reference |
| typedef | reverse_iterator |
| typedef | size_type |
| typedef | value_type |
| QLinkedList () | |
| QLinkedList (const QLinkedList<T> & other ) | |
| QLinkedList (std::initializer_list<T> list ) | |
| QLinkedList (QLinkedList<T> && other ) | |
| ~QLinkedList () | |
| void | append (const T & value ) |
| T & | back () |
| const T & | back () const |
| iterator | begin () |
| const_iterator | begin () const |
| const_iterator | cbegin () const |
| const_iterator | cend () const |
| void | clear () |
| const_iterator | constBegin () const |
| const_iterator | constEnd () const |
| bool | contains (const T & value ) const |
| int | count (const T & value ) const |
| int | count () const |
| const_reverse_iterator | crbegin () const |
| const_reverse_iterator | crend () const |
| bool | empty () const |
| iterator | end () |
| const_iterator | end () const |
| bool | endsWith (const T & value ) const |
| iterator | erase (iterator pos ) |
| iterator | erase (iterator begin , iterator end ) |
| T & | first () |
| const T & | first () const |
| T & | front () |
| const T & | front () const |
| iterator | insert (iterator before , const T & value ) |
| bool | isEmpty () const |
| T & | last () |
| const T & | last () const |
| void | pop_back () |
| void | pop_front () |
| void | prepend (const T & value ) |
| void | push_back (const T & value ) |
| void | push_front (const T & value ) |
| reverse_iterator | rbegin () |
| const_reverse_iterator | rbegin () const |
| int | removeAll (const T & value ) |
| void | removeFirst () |
| void | removeLast () |
| bool | removeOne (const T & value ) |
| reverse_iterator | rend () |
| const_reverse_iterator | rend () const |
| int | size () const |
| bool | startsWith (const T & value ) const |
| void | swap (QLinkedList<T> & other ) |
| T | takeFirst () |
| T | takeLast () |
| std::list<T> | toStdList () const |
| bool | operator!= (const QLinkedList<T> & other ) const |
| QLinkedList<T> | operator+ (const QLinkedList<T> & other ) const |
| QLinkedList<T> & | operator+= (const QLinkedList<T> & other ) |
| QLinkedList<T> & | operator+= (const T & value ) |
| QLinkedList<T> & | operator<< (const QLinkedList<T> & other ) |
| QLinkedList<T> & | operator<< (const T & value ) |
| QLinkedList<T> & | operator= (const QLinkedList<T> & other ) |
| QLinkedList<T> & | operator= (QLinkedList<T> && other ) |
| bool | operator== (const QLinkedList<T> & other ) const |
| QLinkedList<T> | fromStdList (const std::list<T> & list ) |
| QDataStream & | operator<< (QDataStream & out , const QLinkedList<T> & list ) |
| QDataStream & | operator>> (QDataStream & in , QLinkedList<T> & list ) |
The QLinkedList class is a template class that provides linked lists.
QLinkedList <T> is one of Qt's generic 容器類 . It stores a list of values and provides iterator-based access as well as 常量時間 insertions and removals.
QList <T>, QLinkedList <T>, and QVector <T> provide similar functionality. Here's an overview:
Here's an example of a QLinkedList that stores integers and a QLinkedList that stores QTime 值:
QLinkedList<int> integerList; QLinkedList<QTime> timeList;
QLinkedList stores a list of items. The default constructor creates an empty list. To insert items into the list, you can use operator<<():
QLinkedList<QString> list; list << "one" << "two" << "three"; // list: ["one", "two", "three"]
If you want to get the first or last item in a linked list, use first () 或 last (). If you want to remove an item from either end of the list, use removeFirst () 或 removeLast (). If you want to remove all occurrences of a given value in the list, use removeAll ().
A common requirement is to remove the first or last item in the list and do something with it. For this,
QLinkedList
提供
takeFirst
() 和
takeLast
(). Here's a loop that removes the items from a list one at a time and calls
delete
on them:
QLinkedList<QWidget *> list; ... while (!list.isEmpty()) delete list.takeFirst();
QLinkedList
's value type must be an
可賦值數據類型
. This covers most data types that are commonly used, but the compiler won't let you, for example, store a
QWidget
作為值;取而代之,存儲
QWidget
*. A few functions have additional requirements; for example,
contains
() 和
removeAll
() expect the value type to support
operator==()
. These requirements are documented on a per-function basis.
If you want to insert, modify, or remove items in the middle of the list, you must use an iterator. QLinkedList provides both Java 風格迭代器 ( QLinkedListIterator and QMutableLinkedListIterator ) 和 STL 樣式迭代器 ( QLinkedList::const_iterator and QLinkedList::iterator ). See the documentation for these classes for details.
另請參閱 QLinkedListIterator , QMutableLinkedListIterator , QList ,和 QVector .
Qt 樣式同義詞 QLinkedList::const_iterator .
Qt 樣式同義詞 QLinkedList::iterator .
Typedef for const T *. Provided for STL compatibility.
Typedef for const T &. Provided for STL compatibility.
The QLinkedList::const_reverse_iterator typedef provides an STL-style const reverse iterator for QLinkedList .
It is simply a typedef for
std::reverse_iterator<QLinkedList::const_iterator>
.
警告: Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read 隱式共享迭代器問題 .
該 typedef 在 Qt 5.6 引入。
另請參閱 QLinkedList::rbegin (), QLinkedList::rend (), QLinkedList::reverse_iterator ,和 QLinkedList::const_iterator .
typedef 對於 ptrdiff_t。為兼容 STL 提供。
Typedef for T *. Provided for STL compatibility.
Typedef for T &. Provided for STL compatibility.
The QLinkedList::reverse_iterator typedef provides an STL-style non-const reverse iterator for QLinkedList .
It is simply a typedef for
std::reverse_iterator<QLinkedList::iterator>
.
警告: Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read 隱式共享迭代器問題 .
該 typedef 在 Qt 5.6 引入。
另請參閱 QLinkedList::rbegin (), QLinkedList::rend (), QLinkedList::const_reverse_iterator ,和 QLinkedList::iterator .
typedef 對於 int。為兼容 STL 提供。
typedef 對於 T。為兼容 STL 提供。
構造空列錶。
構造副本為 other .
This operation occurs in 常量時間 ,因為 QLinkedList is 隱式共享 . This makes returning a QLinkedList from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and this takes 綫性時間 .
另請參閱 operator= ().
Constructs a list from the std::initializer_list specified by list .
This constructor is only enabled if the compiler supports C++11 initializer lists.
該函數在 Qt 5.2 引入。
移動構造 QLinkedList 實例,使之指嚮同一對象如 other 所指嚮的。
該函數在 Qt 5.2 引入。
Destroys the list. References to the values in the list, and all iterators over this list, become invalid.
插入 value 在列錶末尾。
範例:
QLinkedList<QString> list; list.append("one"); list.append("two"); list.append("three"); // list: ["one", "two", "three"]
This is the same as list.insert( end (), value ).
另請參閱 operator<< (), prepend (),和 insert ().
此函數為兼容 STL (標準模闆庫) 提供。它相當於 last ().
這是重載函數。
返迴 STL 樣式迭代器 指嚮列錶首項。
另請參閱 constBegin () 和 end ().
這是重載函數。
返迴常量 STL 樣式迭代器 指嚮列錶首項。
該函數在 Qt 5.0 引入。
返迴常量 STL 樣式迭代器 pointing to the imaginary item after the last item in the list.
該函數在 Qt 5.0 引入。
Removes all the items in the list.
另請參閱 removeAll ().
返迴常量 STL 樣式迭代器 指嚮列錶首項。
返迴常量 STL 樣式迭代器 pointing to the imaginary item after the last item in the list.
另請參閱 constBegin () 和 end ().
返迴
true
if the list contains an occurrence of
value
;否則返迴
false
.
This function requires the value type to have an implementation of
operator==()
.
另請參閱 QLinkedListIterator::findNext () 和 QLinkedListIterator::findPrevious ().
Returns the number of occurrences of value 在列錶中。
This function requires the value type to have an implementation of
operator==()
.
另請參閱 contains ().
如同 size ().
返迴常量 STL-style reverse iterator pointing to the first item in the list, in reverse order.
該函數在 Qt 5.6 引入。
另請參閱 begin (), rbegin (),和 rend ().
返迴常量 STL-style reverse iterator pointing to one past the last item in the list, in reverse order.
該函數在 Qt 5.6 引入。
另請參閱 end (), rend (),和 rbegin ().
此函數為兼容 STL (標準模闆庫) 提供。它相當於
isEmpty
() 並返迴
true
if the list is empty.
返迴 STL 樣式迭代器 pointing to the imaginary item after the last item in the list.
這是重載函數。
返迴
true
if the list is not empty and its last item is equal to
value
;否則返迴
false
.
該函數在 Qt 4.5 引入。
Removes the item pointed to by the iterator pos from the list, and returns an iterator to the next item in the list (which may be end ()).
另請參閱 insert ().
這是重載函數。
Removes all the items from begin up to (but not including) end .
Returns a reference to the first item in the list. This function assumes that the list isn't empty.
這是重載函數。
[static]
QLinkedList
<
T
> QLinkedList::
fromStdList
(const
std::list
<
T
> &
list
)
返迴 QLinkedList object with the data contained in list . The order of the elements in the QLinkedList is the same as in list .
範例:
std::list<double> stdlist; list.push_back(1.2); list.push_back(0.5); list.push_back(3.14); QLinkedList<double> list = QLinkedList<double>::fromStdList(stdlist);
該函數在 Qt 4.1 引入。
另請參閱 toStdList ().
此函數為兼容 STL (標準模闆庫) 提供。它相當於 first ().
這是重載函數。
插入 value in front of the item pointed to by the iterator before . Returns an iterator pointing at the inserted item.
另請參閱 erase ().
返迴
true
if the list contains no items; otherwise returns false.
另請參閱 size ().
Returns a reference to the last item in the list. This function assumes that the list isn't empty.
這是重載函數。
此函數為兼容 STL (標準模闆庫) 提供。它相當於 removeLast ().
此函數為兼容 STL (標準模闆庫) 提供。它相當於 removeFirst ().
插入 value 在列錶的開頭。
範例:
QLinkedList<QString> list; list.prepend("one"); list.prepend("two"); list.prepend("three"); // list: ["three", "two", "one"]
This is the same as list.insert( begin (), value ).
This function is provided for STL compatibility. It is equivalent to append( value ).
This function is provided for STL compatibility. It is equivalent to prepend( value ).
返迴 STL-style reverse iterator pointing to the first item in the list, in reverse order.
該函數在 Qt 5.6 引入。
另請參閱 begin (), crbegin (),和 rend ().
這是重載函數。
該函數在 Qt 5.6 引入。
Removes all occurrences of value 在列錶中。
範例:
QList<QString> list; list << "sun" << "cloud" << "sun" << "rain"; list.removeAll("sun"); // list: ["cloud", "rain"]
This function requires the value type to have an implementation of
operator==()
.
另請參閱 insert ().
Removes the first item in the list.
This is the same as erase( begin ()).
另請參閱 removeLast () 和 erase ().
Removes the last item in the list.
另請參閱 removeFirst () 和 erase ().
Removes the first occurrences of
value
in the list. Returns
true
當成功時;否則返迴
false
.
範例:
QList<QString> list; list << "sun" << "cloud" << "sun" << "rain"; list.removeOne("sun"); // list: ["cloud", "sun", "rain"]
This function requires the value type to have an implementation of
operator==()
.
該函數在 Qt 4.4 引入。
另請參閱 insert ().
返迴 STL-style reverse iterator pointing to one past the last item in the list, in reverse order.
該函數在 Qt 5.6 引入。
另請參閱 end (), crend (),和 rbegin ().
這是重載函數。
該函數在 Qt 5.6 引入。
Returns the number of items in the list.
返迴
true
if the list is not empty and its first item is equal to
value
;否則返迴
false
.
該函數在 Qt 4.5 引入。
Swaps list other with this list. This operation is very fast and never fails.
該函數在 Qt 4.8 引入。
Removes the first item in the list and returns it.
若不使用返迴值, removeFirst () 效率更高。
另請參閱 takeLast () 和 removeFirst ().
Removes the last item in the list and returns it.
若不使用返迴值, removeLast () 效率更高。
另請參閱 takeFirst () 和 removeLast ().
Returns a std::list object with the data contained in this QLinkedList 。範例:
QLinkedList<double> list; list << 1.2 << 0.5 << 3.14; std::list<double> stdlist = list.toStdList();
該函數在 Qt 4.1 引入。
另請參閱 fromStdList ().
返迴
true
if
other
is not equal to this list; otherwise returns
false
.
Two lists are considered equal if they contain the same values in the same order.
This function requires the value type to implement
operator==()
.
另請參閱 operator== ().
Returns a list that contains all the items in this list followed by all the items in the other 列錶。
另請參閱 operator+= ().
Appends the items of the other list to this list and returns a reference to this list.
另請參閱 operator+ () 和 append ().
這是重載函數。
追加 value to the list.
Appends the items of the other list to this list and returns a reference to this list.
另請參閱 operator+= () 和 append ().
這是重載函數。
追加 value to the list.
賦值 other to this list and returns a reference to this list.
移動賦值 other 到此 QLinkedList 實例。
該函數在 Qt 5.2 引入。
返迴
true
if
other
is equal to this list; otherwise returns false.
Two lists are considered equal if they contain the same values in the same order.
This function requires the value type to implement
operator==()
.
另請參閱 operator!= ().
Writes the linked list list 到流 out .
This function requires the value type to implement
operator<<()
.
另請參閱 QDataStream 運算符格式 .
Reads a linked list from stream in into list .
This function requires the value type to implement
operator>>()
.
另請參閱 QDataStream 運算符格式 .