
DsSet::filter 함수는 집합에서 요소를 필터링할 때 사용됩니다. 필터링 조건이 여러 개일 경우, 여러 조건을 연결하여 사용할 수 있습니다.
예를 들어, 다음과 같이 두 개의 필터링 조건을 지정할 수 있습니다.
#hostingforum.kr
cpp
DsSet* set = DsSetCreate();
// 집합에 요소를 추가합니다.
DsSetAdd(set, 1);
DsSetAdd(set, 2);
DsSetAdd(set, 3);
DsSetAdd(set, 4);
DsSetAdd(set, 5);
// 필터링 조건 1: 요소가 3보다 큰 경우
DsSet* filteredSet1 = DsSetFilter(set, DsSetGreater, 3);
// 필터링 조건 2: 요소가 짝수인 경우
DsSet* filteredSet2 = DsSetFilter(filteredSet1, DsSetEven, 0);
// 결과 집합을 출력합니다.
DsSetPrint(filteredSet2);
위 예제에서, 첫 번째 필터링 조건은 요소가 3보다 큰 경우를 지정하고, 두 번째 필터링 조건은 요소가 짝수인 경우를 지정합니다. 결과 집합은 4와 5만 포함합니다.
또한, 여러 필터링 조건을 논리적으로 연결할 수 있습니다. 예를 들어, 다음과 같이 두 개의 필터링 조건을 논리적으로 연결할 수 있습니다.
#hostingforum.kr
cpp
DsSet* set = DsSetCreate();
// 집합에 요소를 추가합니다.
DsSetAdd(set, 1);
DsSetAdd(set, 2);
DsSetAdd(set, 3);
DsSetAdd(set, 4);
DsSetAdd(set, 5);
// 필터링 조건 1: 요소가 3보다 큰 경우
DsSet* filteredSet1 = DsSetFilter(set, DsSetGreater, 3);
// 필터링 조건 2: 요소가 짝수인 경우
DsSet* filteredSet2 = DsSetFilter(filteredSet1, DsSetEven, 0);
// 필터링 조건 3: 요소가 5보다 작은 경우
DsSet* filteredSet3 = DsSetFilter(filteredSet2, DsSetLess, 5);
// 결과 집합을 출력합니다.
DsSetPrint(filteredSet3);
위 예제에서, 첫 번째 필터링 조건은 요소가 3보다 큰 경우를 지정하고, 두 번째 필터링 조건은 요소가 짝수인 경우를 지정합니다. 세 번째 필터링 조건은 요소가 5보다 작은 경우를 지정합니다. 결과 집합은 4만 포함합니다.
2025-07-14 06:17