QLinkedList才是Qt真正意义上的链表。QList提供的所有基于索引的操作,QLinkedList都是不可能支持的

QLinkedList

http://www.cnblogs.com/findumars/p/5176081.html

QLinkedList才是Qt真正意义上的链表。QLinkedList实际上跟std::list是一样的,也是双向链表。QList实际内部还是一个指针数组。QLinkedList提供的函数大部分还是跟QList一样的,下面我们就看一些不同的地方。

 

int QLinkedList::size () const

返回链表的大小,即节点个数。而forward_list没有这个函数。

 

const_iterator QList::constBegin () const

const_iterator QList::constEnd () const

这是QList返回STL风格的迭代器。QLinkedList则没有提供这样的函数。

 

void QList::append ( const T & value )

void QList::append ( const QList<T> & value )

 

void QLinkedList::append ( const T & value )

QLinkedList 没有接受一个QLinkedList 参数的append函数。

 

最重要的区别就是:

QLinkedList没有 T &

operator[] ( int i )

链表是肯定不能支持索引操作的。

所以QList提供的所有基于索引的操作,QLinkedList都是不可能支持的,比如:

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 )

可能还有其他函数,这里就不一一列举了。

QLinkedList提供了与std::list的转换函数:

QLinkedList<T>

fromStdList ( const std::list<T> & list )

std::list<T>QLinkedList::toStdList () const

需要记住的一点:Qt容器是隐式共享的。QLinkedList自然也是支持隐式共享的。

http://blog.csdn.net/hai200501019/article/details/11787097

 
分类: Qt-容器
 
posted @ 2018-04-18 17:41  sky20080101  阅读(1992)  评论(0)    收藏  举报