#include <iostream>
#include <vector>
#include <list>
#include <hash_map>
#include <string>
#pragma warning(disable : 4786)
std::vector<int> v1;
std::list<int> l1;
std::hash_map<std::string, int> h1;
void Test(std::list<int> test);
void main(void)
{
// vector 사용 예제.
v1.resize(2);
v1[0] = 10;
v1[1] = 20;
v1.resize(3);
v1[2] = 30;
v1.push_back(40);
std::cout << "vector 내의 원소의 수 = " << v1.size() << std::endl;
std::vector<int>::iterator iv;
for(iv = v1.begin(); iv != v1.end();)
{
std::cout << *iv << " ";
if(*iv == 10)
{
v1.erase(iv++); // iv 먼저 지워주고 후에, iv증가
}
else
{
iv++;
}
}
std::cout << std::endl;
///////////////////////////////////////////////////////////////////////////
// list 사용 예제.
l1.push_back(10);
l1.push_back(20);
l1.push_back(30);
l1.push_back(40);
std::list<int>::iterator i1 = l1.begin();
i1++;
i1++;
l1.insert(i1, 30);
for(i1 = l1.begin(); i1 != l1.end();)
{
std::cout << *i1 << " ";
if(*i1 == 10)
{
l1.erase(i1++);
}
else
{
i1++;
}
}
std::cout << std::endl;
////////////////////////////////////////
Test(l1);
////////////////////////////////////////
for(i1 = l1.begin(); i1 != l1.end(); i1++)
{
std::cout << *i1 << " ";
}
std::cout << "실험" << std::endl;
std::list<int>::reverse_iterator ri1;
for(ri1 = l1.rbegin(); ri1 != l1.rend(); ri1++)
{
std::cout << *ri1 << " ";
}
std::cout << std::endl;
//////////////////////////////////////////////////////////////////////////////////////
// hash_map 사용 예제
std::hash_map<std::string, int>::value_type value("겨자", 10);
h1.insert(value);
h1["열혈"] = 20;
h1["짱구"] = 30;
std::hash_map<std::string, int>::iterator ih;
// std::list<int>::iterator i2 = h1.begin();
for(ih = h1.begin(); ih != h1.end(); ih++)
{
std::cout << ih->first << " " << ih->second << " ";
}
std::cout << std::endl;
ih = h1.find("겨자");
if(ih != h1.end())
{
std::cout << std::endl;
std::cout << ih->first << " " << ih->second << " " << std::endl;
}
}
void Test(std::list<int> test)
{
std::list<int>::iterator ih;
std::cout << "리스트 테스트" << std::endl;
for(ih = test.begin(); ih != test.end();)
{
std::cout << *ih << " ";
if(*ih == 20)
{
test.erase(ih++);
}
else
{
ih++;
}
}
std::cout << "리스트 테스트" << std::endl;
}