Programming/c++
-
[c++] std::partition_pointProgramming/c++ 2022. 12. 26. 14:04
1.함수 헤더 파일 #include 2.함수 원형 template ForwardIterator partition_point( ForwardIterator first, ForwardIterator last, UnaryPredicate pred); 조건을 충족하지 않는 지정된 범위의 첫 번째 요소를 반환합니다. 조건을 충족하는 요소가 그렇지 않은 요소 앞에 오도록 요소가 정렬됩니다. 3.return 값(반환 값) 반복자를 반환합니다. 테스트한 조건을 충족하지 않는 첫 번째 요소의 반복자, 반환하는 pred에서 last 반복자까지 찾을 수 없는 경우 4.예제 std::vector vec2 {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; auto point = std::partition_point(v..
-
[c++] std::stable_partitionProgramming/c++ 2022. 12. 24. 18:40
1.함수 헤더 파일 #include 2.함수 원형 template BidirectionalIterator stable_partition( BidirectionalIterator first, BidirectionalIterator last, UnaryPredicate pred ); template BidirectionalIterator stable_partition( ExecutionPolicy&& exec, BidirectionalIterator first, BidirectionalIterator last, UnaryPredicate pred); 참조된 범위는 유효해야 하고 모든 포인터는 역참조 가능해야 하며 시퀀스 내에서 처음 위치에서 증분하여 마지막 위치까지 도달할 수 있어야 합니다. pred는 사용..
-
[C++] 비트 연산, Bitwise ( 10진수를 2진수로 변환)Programming/c++ 2022. 12. 13. 19:43
비트 연산을 이용해서 쉽게 10진수를 2진수로 변환할 수 있다. int main(){ int num = 52; for(int i = 7; i>= 0; i--){ //2진수 표현 자릿수, 자릿수는 늘려도 된다. int result = num >> i & 1; printf_s("%d", result); //00110100 } return 0; } ( num >> i ) : i 자릿수 만큼 오른쪽으로 shift 연산을 실행한다. ( i & 1 ) : 2^0 자릿수를 추출하기 위한 AND연산이다. 52(10진수) 를 2진수로 변환하면 00110100(2진수) 로 변환된다. 곱하기, 나머지 계산을 이용해서 비트 연산을 하지 않아도 위의 비트 연산을 이용하면 더 간단하게 식을 구현할 수 있다.
-
[VSCode] c++17 설정Programming/c++ 2022. 12. 3. 13:27
visual studio code에서 c++를 잘 사용해왔는데, C++17버전에서는 잘 돌아가는 문법이 내가 사용하고 있는 VSCode에서는 적용되지 않아 C++17로 변경하였다. C++ 컴파일러를 C++17로 설정하는 방법을 포스팅하겠습니다~ 1. F1 > c/c++ configurations 에서 c17, c++17을 선택합니다. 이 항목만 설정한다고 c++17이 설정되지 않습니다. 2. c_cpp_properities.json 파일을 수정합니다. "cStandard": "c17", "cppStandard": "c++17", "compilerArgs": ["-std=c++17", "-stdlib=libc++"] 3. tasks.json 파일도 수정합니다. "-std=c++17", 4. 빌드 확인 C+..
-
[c++] Stable_sort() vs Sort() 함수 차이Programming/c++ 2022. 11. 24. 22:59
1.함수 헤더 파일 #include 2.함수 원형 -sort 함수 // < 를 이용한 비교 (1) template void sort(RandomIt first, RandomIt last); // 비교 함수 (comp) 를 이용한 비교 (2) template void sort(RandomIt first, RandomIt last, Compare comp); // Execution policy 를 지정한 경우 (3) template void sort(ExecutionPolicy&& policy, RandomIt first, RandomIt last); template void sort(ExecutionPolicy&& policy, RandomIt first, RandomIt last, Compare comp..
-
[c++] prev_permutation, next_permutationProgramming/c++ 2022. 9. 28. 12:03
중복을 제외한 순열(permutation)을 구할 때 사용하는 함수입니다. 수학적으로 순열이란, 서로 다른 n개의 원소에서 r개를 뽑아 한 줄로 세우는 경우의 수를 말합니다. 원소를 한 줄로 세우기 때문에 원소의 조합이 같더라도 순서가 다르면 다른 방법으로 봅니다. {1, 2, 3}원소의 모든 순열을 구하면, {1, 2, 3} {1, 3, 2} {2, 1, 3} {2, 3, 1} {3, 1, 2} {3, 2, 1} 총 6가지가 나옵니다. c++의 algorithm헤더에서 제공하는 순열을 구하는 함수는 아래와 같이 2가지 입니다. next_permutation prev_permutation // default bool next_permutation (BidirectionalIterator first, Bi..