Qt5 Tutorial QLinkedList - 2020
bogotobogo.com site search:
QLinkedList
In this tutorial, we will learn about QLinkedList.
The QLinkedList class is a template class that provides linked lists.
QLinkedList<T> is one of Qt's generic container classes. It stores a list of values and provides iterator-based access as well as constant time insertions and removals.
Index lookup | Insertion | Prepending | Appending | |
---|---|---|---|---|
QLinkedList<T> | O(n) | O(1) | O(1) | O(1) |
QList<T> | O(1) | O(n) | Amort. O(1) | Amort. O(1) |
QVector<T> | O(1) | O(n) | O(n) | Amort. O(1) |
#include <QCoreApplication> #include <QLinkedList> #include <QDebug> #include <QString> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QLinkedList<QString> List; List << "A" << "B" << "C"; List.append("D"); List.append("E"); List.append("F"); foreach(QString s, List) qDebug() << s; return a.exec(); }
Output:
"A" "B" "C" "D" "E" "F"
QLinkedList stores a list of items. The default constructor creates an empty list. To insert items into the list, we can use operator<<().
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization