# include <Qlist>
# include <list>
# include <functional>
# include <string>
模板函数
template < class _Ty > void PrintfList ( QList< _Ty> data)
{ qDebug ( ) << "模板函数" << "\t" ; for ( auto v : data) { qDebug ( ) << v << "\t" ; } qDebug ( ) << "\n" ;
}
基本操作
QString tmepList[ 5 ] = { "3医院" , "1学校" , "9学位" , "0衣" , "2行" } ; QList< QString> strList; for ( int i = 0 ; i < 5 ; i++ ) { strList. push_back ( tmepList[ i] ) ; } strList. push_front ( "10胶水" ) ; for ( int i = 0 ; i < strList. size ( ) ; i++ ) { qDebug ( ) << strList[ i] << "\n" ; } PrintfList ( strList) ; qDebug ( ) << "迭代器打印" ; for ( QList< QString> :: iterator iter = strList. begin ( ) ; iter != strList. end ( ) ; iter++ ) { qDebug ( ) << * iter << "\n" ; } strList. sort ( ) ; PrintfList ( strList) ; qDebug ( ) << "反转打印" ; strList. reserve ( strList. size ( ) ) ; PrintfList ( strList) ;
while ( ! strList. empty ( ) ) { qDebug ( ) << strList. front ( ) << "\t" ; strList. pop_front ( ) ; } qDebug ( ) << "strList size:" << strList. size ( ) << "\n" ;