Skip to content

Commit

Permalink
qsort
Browse files Browse the repository at this point in the history
  • Loading branch information
hyejun committed Jun 15, 2020
1 parent 00a493b commit feeabcd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions qsort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>

int compare(const void* a, const void* b) {
int num1 = *(int*)a;
int num2 = *(int*)b;
if (num1 < num2) return -1;
if (num1 > num2) return 1;

return 0;
}

int main() {
int numArr[10], i;
for (i = 0; i < 10; i++) {
scanf("%d", &numArr[i]);
}

qsort(numArr, sizeof(numArr) / sizeof(int), sizeof(int), compare);

for (i = 0; i < 10; i++) {
printf("%d ", numArr[i]);
} printf("\n");

return 0;
}

0 comments on commit feeabcd

Please sign in to comment.