#include<iostream>
using namespace std;
#include<set>
void printSet(set<int> st)
{
for (set<int>::const_iterator it = st.begin(); it != st.end(); it++)
{
cout << (*it) << " ";
}
cout << endl;
}
void test0201()
{
set<int> s1;
s1.insert(10);
s1.insert(20);
s1.insert(30);
s1.insert(40);
printSet(s1);
if (s1.empty())
{
cout << "s1为空" << endl;
}
else
{
cout << "s1不为空" << endl;
cout << "s1大小:" << s1.size() << endl;
}
set<int> s2;
s2.insert(1098);
s2.insert(5000);
s2.insert(30897);
s2.insert(40689);
cout << "交换前:" << endl;
printSet(s1);
printSet(s2);
cout << "交换后:" << endl;
s1.swap(s2);
printSet(s1);
printSet(s2);
}
int main()
{
test0201();
system("pause");
return 0;
}
网友评论