C[ | ]
C
Copy
#include <stdlib.h>
int *distinct(const int *values, size_t count, size_t *pResultCount) {
int* res = calloc(count, sizeof(int));
int resCount = 0;
for(int i=0; i<count; i++) {
char exist = 0;
for(int j=0; j<resCount; j++) {
if( res[j] == values[i] ) {
exist = 1;
break;
}
}
if( exist ) continue;
res[resCount] = values[i];
resCount++;
}
*pResultCount = resCount;
return res;
}
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.