Skip to content

Instantly share code, notes, and snippets.

@HMKRL
Created December 22, 2020 08:51
Show Gist options
  • Save HMKRL/2f65d9bb03936c15049e2ea7454c60e4 to your computer and use it in GitHub Desktop.
Save HMKRL/2f65d9bb03936c15049e2ea7454c60e4 to your computer and use it in GitHub Desktop.
#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