250x250
Notice
Recent Posts
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
관리 메뉴

일상 코딩

[C++/CPP] 16.03. STL algorithm 본문

C++/따배C++ 16강 STL

[C++/CPP] 16.03. STL algorithm

polarcompass 2022. 1. 5. 02:16
728x90
C++ 온라인 컴파일러 사이트
  1. https://replit.com/~
  2. https://www.onlinegdb.com/online_c++_compiler
  3. https://cpp.sh/
  4. https://www.tutorialspoint.com/compile_cpp_online.php
#include<iostream>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    {
        vector<int> container;
        for (int i = 0; i < 10; ++i)
            container.push_back(i);
        
        auto itr = std::min_element(container.begin(), container.end());
        cout << *itr << endl;
        
        itr = std::max_element(container.begin(), container.end());
        cout << *itr << endl;

        // 특정 위치를 가리키고 있고, 
        itr = std::find(container.begin(), container.end(), 3);
        // 특정 수를 집어 넣는다.
        // 3은 뒤로 밀리고, 128이 들어가게됨.
        container.insert(itr, 128);

        for(auto& e:container)
            cout << e << " ";
        cout << endl;

        std::sort(container.begin(), container.end());

        for(auto& e:container)
            cout << e << " ";
        cout << endl;

        // std::sort_heap(container.begin(), container.end());

        // for(auto& e:container)
        //     cout << e << " ";
        // cout << endl;

        std::reverse(container.begin(), container.end());

        for(auto& e:container)
            cout << e << " ";
        cout << endl;

    }

    // container 별로 함수 적용 방법이 다름.
    // vector는 std:: 로 불러오고
    // list는 container. 으로 불러온다.

    return 0;
}
728x90