#include<iostream>
#include<deque>
#include<vector>
#include<stack>
#include<algorithm>
#include<Queue>
#include<ctime>
#include<list>
#include<set>
#include<map>
using namespace std;
//map容器 构造和赋值
//map中所有元素都是成对出现,插入数据时候需要使用队组
void printMap(map<int,int>&m)
{
for (map<int, int>::iterator it = m.begin(); it != m.end(); it++)
{
cout << "key 值:" << (*it).first << "元素值:" << (*it).second << endl;
}
cout << "--------------" << endl;
}
void test01()
{
map<int, int>m;
m.insert(pair<int, int>(1, 10));
m.insert(pair<int, int>(2, 30));
m.insert(pair<int, int>(3, 20));
m.insert(pair<int, int>(4, 40));
printMap(m);
//拷贝构造
map<int, int>m2(m);
printMap(m2);
//赋值
map<int, int>m3;
m3 = m2;
printMap(m3);
}
void test02()
{
}
int main()
{
test01();
//test02();
system("pause");
return 0;
}
#include<iostream>
#include<deque>
#include<vector>
#include<stack>
#include<algorithm>
#include<Queue>
#include<ctime>
#include<list>
#include<set>
#include<map>
using namespace std;
//map容器 大小和交换
void printMap(map<int,int>&m)
{
for (map<int, int>::iterator it = m.begin(); it != m.end(); it++)
{
cout << "key 值:" << (*it).first << "元素值:" << (*it).second << endl;
}
cout << "--------------" << endl;
}
void test01()
{
map<int, int>m;
m.insert(pair<int, int>(1, 10));
m.insert(pair<int, int>(2, 30));
m.insert(pair<int, int>(3, 20));
m.insert(pair<int, int>(4, 40));
printMap(m);
if (m.empty())
{
cout << "m is empty" << endl;
}
else
{
cout << "m is not empty" << endl;
cout << "m的大小为:" << m.size() << endl;
}
}
void test02()
{
map<int, int>m;
m.insert(pair<int, int>(1, 10));
m.insert(pair<int, int>(2, 30));
m.insert(pair<int, int>(3, 20));
m.insert(pair<int, int>(4, 40));
printMap(m);
map<int, int>m2;
m2.insert(pair<int, int>(1, 11));
m2.insert(pair<int, int>(2, 33));
m2.insert(pair<int, int>(3, 22));
m2.insert(pair<int, int>(4, 44));
printMap(m2);
m.swap(m2);
printMap(m);
printMap(m2);
}
int main()
{
//test01();
test02();
system("pause");
return 0;
}