c 工程基礎之STL系列 (三) set

2021-06-19 14:28:58 字數 562 閱讀 2148

set也是在工程中常用的資料結構,在需要快速查詢和插入的場景,也適合一些排重和需要按關鍵字排序插入的場景。multiset使用的場景應該不是太多,下面主要介紹下set中一些常用的方法。

#include

#include

using namespace std;

struct node

};int main()

for(set::iterator it = a.begin(); it != a.end(); ++it)

for(set::iterator it = a.begin(); it != a.end(); ++it)

cout<<"size="<

//結構體和class需要過載小於號

node t1 = ;

node t2 = ;

node t3 = ;

setb;

b.insert(t1);

coutcoutcout<<"size="if(b.find(t3) != b.end())cout<<"yes"cout<<"size="cout<<"size="<

}

c 工程基礎之STL系列 (一) vector

stl在c 實際工程中很重要,可以提供開發效率降低維護成本,實際開發中可能大家並不需要了解其內部實現,但了解大概的資料結構還是有好處的。首先講下幾個在工程中stl的幾個典型問題 1.判斷容器為不為空empty 複雜度是o 1 而用size 0可能是o n 2.clear 並不能釋放記憶體,用swap...

STL系列之六 set與hash set

stl系列之六 set與hash set set和hash set是stl中比較重要的容器,有必要對其進行深入了解。在stl中,set是以紅黑樹 rb tree 作為底層資料結構的,hash set是以hash table 雜湊表 作為底層資料結構的。set可以在時間複雜度為o logn 情況下插入...

STL系列之六 set與hash set

stl系列之六 set與hash set set和hash set是stl中比較重要的容器,有必要對其進行深入了解。在stl中,set是以紅黑樹 rb tree 作為底層資料結構的,hash set是以hash table 雜湊表 作為底層資料結構的。set可以在時間複雜度為o logn 情況下插入...