Created
December 22, 2020 08:51
-
-
Save HMKRL/2f65d9bb03936c15049e2ea7454c60e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define N 10 | |
int cmp(const void *a, const void *b) { | |
int *aptr = (int*) a; | |
int *bptr = (int*) b; | |
if(*aptr < *bptr) return -1; | |
if(*aptr == *bptr) return 0; | |
if(*aptr > *bptr) return 1; | |
} | |
int main() | |
{ | |
int arr[N] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3 }; | |
qsort(arr, N, sizeof(int), cmp); | |
for(int i = 0;i < N;++i) { | |
printf("%d ", arr[i]); | |
} | |
puts(""); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment