ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • std::vector
    알고리즘/c++ 주요 문법 2017. 7. 22. 22:19
    반응형

    http://hyeonstorage.tistory.com/324 참고


    #include <vector>
    #include <stdio.h>
    #include <functional>
    #include <algorithm>

    using namespace std;


    int main(){

    vector<int> v;

    v.push_back(10);
    v.push_back(20);
    v.push_back(30);
    printf("%d\n", v.at(0));
    printf("%d\n", v.at(v.size()-1));
    printf("%lu\n", v.size());
    v.clear();
    if(v.empty()){
    printf("empty~\n");
    }
    v.push_back(30);
    v.push_back(10);
    v.push_back(20);
    sort(v.begin(), v.end());
    for(int i=0; i<v.size(); ++i){
    printf("%d ", v[i]);
    }
    printf("\n");
    sort(v.begin(), v.begin()+v.size(), greater<int>());
    for(int i=0; i<v.size(); ++i){
    printf("%d ", v[i]);
    }
    printf("finish~\n");

    return 0;

    }


    반응형

    '알고리즘 > c++ 주요 문법' 카테고리의 다른 글

    std::queue  (0) 2017.07.31

    댓글

Designed by Tistory.