///////////////////////////////////////////////////////////////////////////////
//STL( map )
//map의 index에 의해서 정렬되어 값이 출력됨.
//index키값을 이용해 신속하게 값을 찾을 수 있다.
//중복된 index를 허용하지 않는다.
//정력컨테이너 : 키값을 이용해서 데이터를 신속하게 찾을 수 있다.
///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <map>

 

using namespace std;

 

void main()
{
    map<int, char*> map1;
    map<int, char*>::iterator it;

    map1[3] = "yi";
    map1[2] = "ki";
    map1[1] = "ho";

 

    for( it = map1.begin(); it != map1.end(); it++ )

    {
        cout << it->first << it->second << endl;
    }

 

    map1[1] = "wow";
    map1[3] = "hi";

 

    for( it = map1.begin(); it != map1.end(); it++ )

    {
        cout << it->first << it->second << endl;
    }

 

    map1.erase(3);  //index키값을 이용해 쉽게 자료를 삭제할 수도 있다.

   

    for( it = map1.begin(); it != map1.end(); it++ )

    {
        cout << it->first << it->second << endl;
    }
}


///////////////////////////////////////////////////////////////////////////////
//STL( set )
//렌덤하게 값을 집어 넣으면서 소트와 중복된 값을 뺀다.
//정렬컨테이너
///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <set>
#include <ctime>

 

using namespace std;

 

void main()
{
    srand((unsigned)time(NULL));
    set<int> set1;
    set<int>::iterator it;

    int p[8] = { 5, 3, 2, 4, 1, 9, 8, 7 };

 

    for( int i = 0; i < 8; i++ )

    {
        int temp = rand() % 8;
        set1.insert(p[temp]);
    }

 

    for( it = set1.begin(); it != set1.end(); it++ )

    {
        cout << *it << endl;
    }
}


'Programming > STL' 카테고리의 다른 글

list  (0) 2010.11.16
map - map의 index에 의해 정렬되어 값이 출력  (0) 2010.11.16
stack  (0) 2010.11.16
vector - 가변길이의 순차적인 배열에 대한 임의의 접근 가능  (0) 2010.11.16

///////////////////////////////////////////////////////////////////////////////
//STL( stack )
///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <stack>

 

using namespace std;

 

void main()
{
    stack<int> stack1;

 

    //추가
    stack1.push(5);
    stack1.push(3);
    stack1.push(7);

 

    //삭제
    cout << stack1.top() << endl;

    stack1.pop();

    cout << stack1.top() << endl;

    stack1.pop();

    cout << stack1.top() << endl;
}


+ Recent posts