資源描述:
《總結(jié):c++ stl 容器》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、總結(jié):C++STL容器STL的叫法是“容器”,標(biāo)準(zhǔn)庫里面容器不多,數(shù)組、鏈表、紅黑樹,實(shí)現(xiàn)都不負(fù)責(zé)threadsafe、mutable之類,對(duì)比下Java的,選擇很多,也挺混亂。。序列容器:動(dòng)態(tài)數(shù)組vector,雙端隊(duì)列deque(本質(zhì)是動(dòng)態(tài)數(shù)組加索引),鏈表list。關(guān)聯(lián)容器:set,map,multiset,multimap,bitset(叫bit_array更合適)。容器適配器:stack,queue,priority_queue。除了bitset,都用到模板,聲明大概是這樣的:STLStandardCont
2、ainers,點(diǎn)擊加號(hào)展開!STLContainerAdaptors,點(diǎn)擊加號(hào)展開!C++是注重效率的,所以STL很強(qiáng)調(diào)一點(diǎn)就是amortized的性能,下面的表很不錯(cuò),還可以用來速查:?SequencecontainersAssociativecontainersHeaders
3、onstructorconstructorconstructorconstructorconstructorconstructorconstructordestructorO(n)destructordestructordestructordestructordestructordestructordestructoroperator=O(n)operator=operator=operator=operator=operator=operator=operator=operatorsiteratorsbeginO
4、(1)beginbeginbeginbeginbeginbeginbeginendO(1)endendendendendendendrbeginO(1)rbeginrbeginrbeginrbeginrbeginrbeginrbeginrendO(1)rendrendrendrendrendrendrendcapacitysize*sizesizesizesizesizesizesizesizemax_size*max_sizemax_sizemax_sizemax_sizemax_sizemax_sizemax_
5、sizeemptyO(1)emptyemptyemptyemptyemptyemptyemptyresizeO(n)resizeresizeresizeelementaccessfrontO(1)frontfrontfrontbackO(1)backbackbackoperator[]*operator[]operator[]operator[]operator[]atO(1)atatmodifiersassignO(n)assignassignassigninsert*insertinsertinsertinse
6、rtinsertinsertinserterase*eraseeraseeraseeraseeraseeraseeraseswapO(1)swapswapswapswapswapswapswapclearO(n)clearclearclearclearclearclearclearpush_frontO(1)push_frontpush_frontpop_frontO(1)pop_frontpop_frontpush_backO(1)push_backpush_backpush_backpop_backO(1)po
7、p_backpop_backpop_backobserverskey_compO(1)key_compkey_compkey_compkey_compvalue_compO(1)value_compvalue_compvalue_compvalue_compoperationsfindO(logn)findfindfindfindcountO(logn)countcountcountcountcountlower_boundO(logn)lower_boundlower_boundlower_boundlower_
8、boundupper_boundO(logn)upper_boundupper_boundupper_boundupper_boundequal_rangeO(logn)equal_rangeequal_rangeequal_rangeequal_rangeuniquememberscapacityreservesplice?remove?remove_if