QLinkedList<QString> list;
list<<"1"<<"2"<<"3"<<"4";
// foreach正序:
QString str;
foreach (str, list)
qDebug() << str;
// 迭代器正序
QLinkedList<QString>::iterator it;
for(it = list.begin(); it != list.end(); ++it){
qDebug() << *it;
}
// 迭代器倒序
QLinkedList<QString>::const_iterator it = list.constEnd();
while (it != list.constBegin())
{
--it;
qDebug()<<*it;
}
移除某个节点
list.removeOne("4");
列表大小
list.size()
链头位置插入
list.push_front("5");
链尾位置插入
list.push_back("5");
清空
list.clear();
参考:
1.QLinkedList用法
2.Qt容器类——1. QList类、QLinkedList类和QVector类
3.Qt容器类之二:迭代器