ComputerScience/STL
-
[C++/STL] set은 무엇인가? [중복제거용, 존재체크용]ComputerScience/STL 2020. 5. 27. 23:35
set이라는 애를 배워보자... std::set is an associative container that contains a sorted set of unique objects of type Key. Sorting is done using the key comparison function Compare. Search, removal, and insertion operations have logarithmic complexity. Sets are usually implemented as red-black tree. 무엇인가 하오니 해석해보면 set은 타입키의 고유한(중복이 없는) 객체의 정렬된 세트를 포함하는 연관 콘테이너이다. 정렬은 Compare함수를 통한 정렬을 통해 이루어진다. 검색, 제거, 삽입..
-
[C++/priority_queue/operator overloading] 우선순위 큐 struct 연산자 오버로딩ComputerScience/STL 2020. 5. 24. 19:39
priority_queue는 기본적으로 max_heap을 가지고 있다. 어떻게 넣던간에 max_heap으로 저장이 되고 pop()할 때 마다 가장 큰 값이 나온다. 그런데 문제는 priority_queue(이하 pQ)안에 int형이 아닌 구조체나 클래스가 들어갈 수도 있는 것이고 여기서 우리가 정렬하고 싶은 방법이 있을 수 있다는 것 (예를 들면, x,y,z를 갖고 있는 구조체를 pQ에 넣을 때, z의 크기를 기준으로 heap을 만들고 싶다) 그럴 땐, 이와 같이 코드를 작성한다. #include #include #include using namespace std; struct Object { int x; int y; int z; Object(int a, int b,int c) { x = a; y = b..
-
C++/연산자 오버로딩/operatior overloadingComputerScience/STL 2020. 5. 24. 17:58
연산자 오버로딩이 어려워 정리해봤다 #include #include #include #include using namespace std; bool cmp_func1(const int& a, const int& b) { return a b; } struct cmp_struct1{ bool operator()(const int& x, const int& y) { return x y; } }; int main() { priority_queue q..
-
[C++/STL]VectorComputerScience/STL 2020. 5. 21. 01:28
C/C++의 배열을 동적으로 사용할 수 있는 형태의 Container (전공 프로젝트 중 처음 알게 됐고 매우 편하다) #include using namespace std; 위와 같이 라이브러리를 import 해줘야 사용할 수 있다. 거의 코테할 때 기본적으로 import해주는 편 또한 vector를 사용할 때, std::를 일일히 써줄 필요 없이 using namespace std; 를 선언하면 된다. vector v; vector v; vector v(n); vector v(n,a); vector v1(v2); 생성은 다음과 같다. vector v; data type을 가진 vector를 만들어준다. 보통은 int를 많이 쓰는 편임 편의를 위해 int형으로 선언하겠습니다. vector v; 와 같이 ..