當前位置:編程學習大全網 - 網站源碼 - 如何能夠快速合並兩個stl的set

如何能夠快速合並兩個stl的set

下面用的是set自己的插入函數,應該也沒有什麽更快的了吧,希望對妳有用

#include?<iostream>

#include?<set>

using?namespace?std;

template<typename?T>

void?print_container(const?T&?c)

{

for?(auto?iter?=?c.begin();iter?!=?c.end();++iter)

{

cout<<*iter<<"?";

}

cout<<endl;

}

int?main?(int,?char?*[])

{

set<int>?set_a,set_b;

for?(int?i=0;i<20;++i)

{

if?(i%2==0)

{

set_a.insert(i);

}

else

{

set_b.insert(i);

}

}

print_container(set_a);

print_container(set_b);

set<int>?set_ab(set_a.begin(),set_a.end());

set_ab.insert(set_b.begin(),set_b.end());

print_container(set_ab);

return?0;

}

0 2 4 6 8 10 12 14 16 18

1 3 5 7 9 11 13 15 17 19

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

請按任意鍵繼續. . .

  • 上一篇:java混淆器是做什麽的?
  • 下一篇:急需壹個能用的極品飛車10的序列號!!拜托各位了
  • copyright 2024編程學習大全網