qsort(array,array_len,sizeof(int),compare);
*오름차순
int compare(const void *a , const void *b){
if(*(int*)a > *(int*)b) return 1;
else if(*(int*)a < *(int*)b) return -1;
else return 0;
}
*내림차순
int compare(const void *a , const void *b){
if(*(int*)a < *(int*)b) return 1;
else if(*(int*)a > *(int*)b) return -1;
else return 0;
}
'전공부셔 > c' 카테고리의 다른 글
calloc과 malloc 차이 (0) | 2023.03.05 |
---|---|
[프로그래머스] 문자 반복 출력하기 (1) | 2023.02.27 |
[프로그래머스] 숨어있는 숫자의 덧셈 (1) (0) | 2023.02.26 |
배열 원소 개수 (0) | 2023.02.26 |
[프로그래머스] 문자열 뒤집기 (0) | 2023.02.26 |