List的實現總結

STL_list的實現方法總結
list是一個在常數範圍內在任意位置進行插入和刪除的序列式容器,可進行雙向迭代;底層是雙向鏈表結構;與forword_list類似,區別在forword_list是單鏈表;而與其餘序列式容器相比(array,vector,deque),list的優點在於能夠在任意位置插入,缺點在於不能在任意位置訪問;ide

1)list<int> mylist;
2)list<int> mylist(10) //此處可直接制定表項數量(10),也能夠指定內容如(10,1),後者表示值域爲1;
3)list<int> mylist1(mylist)//此爲拷貝調用
4)list<int> mylist = {1,2,3,4};
5)list<int> mylist1(mylist.begin(),mylist.end());//此爲迭代器法code

[]操做不能用於訪問list,訪問list可以使用迭代器法:
     list<int>::iterator it = mylist.begin();
     while(it != mylist.end())
     {
          cout<<*it<<"  ";
                ++it;
     }cout<<endl;

(未完待續)it

相關文章
相關標籤/搜索