Make Unreal REAL.
article thumbnail

 

insert() 함수로 값을 추가할 때 vector와 set의 인자가 다른 것을 발견했다.

 

vector는 반복자를 첫 번째 인자로 받는 반면 set은 값만을 받는다.

 

#include <iostream>
#include <vector>
#include <set>

using namespace std;

void main()
{
    vector<int> v1 = {1, 2};
    vector<int> v2 = {3, 4};

    v1.insert(v1.end(), v2.begin(), v2.end());

    set<int> st = {1, 2};

    st.insert(v2.begin(), v2.end());
}

 

생각해보니 이유는 간단했다.

 

vector는 임의 위치에 원소를 추가할 수 있기 때문에 가능하지만 set은 정렬된 상태를 유지하기 때문에 원하는 위치에 원소를 추가할 수 없기 때문이다.

profile

Make Unreal REAL.

@diesuki4

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그