您好,登錄后才能下訂單哦!
STL_list的實(shí)現(xiàn)方法總結(jié)
list是一個在常數(shù)范圍內(nèi)在任意位置進(jìn)行插入和刪除的序列式容器,可進(jìn)行雙向迭代;底層是雙向鏈表結(jié)構(gòu);與forword_list相似,區(qū)別在forword_list是單鏈表;而與其他序列式容器相比(array,vector,deque),list的優(yōu)勢在于可以在任意位置插入,缺點(diǎn)在于不能在任意位置訪問;
1)list<int> mylist;
2)list<int> mylist(10) //此處可直接制定表項(xiàng)數(shù)量(10),也可以指定內(nèi)容如(10,1),后者表示值域?yàn)?;
3)list<int> mylist1(mylist)//此為拷貝調(diào)用
4)list<int> mylist = {1,2,3,4};
5)list<int> mylist1(mylist.begin(),mylist.end());//此為迭代器法
[]操作不能用于訪問list,訪問list可使用迭代器法:
list<int>::iterator it = mylist.begin();
while(it != mylist.end())
{
cout<<*it<<" ";
++it;
}cout<<endl;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。