Skip to content

Instantly share code, notes, and snippets.

@aguegu
Created September 28, 2013 01:50
Show Gist options
  • Save aguegu/6737549 to your computer and use it in GitHub Desktop.
Save aguegu/6737549 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstdlib>
int compare (const void * a, const void * b) {
return ( *(int*)b - *(int*)a );
}
void max(int *buff, int length, int * p1, int *p2) {
qsort(buff, length, sizeof(int), compare);
*p1 = buff[0];
*p2 = buff[1];
}
int main(int argc, char **argv) {
printf ("hello, world.");
int s[4] = {0, 1, 2, 3};
int max1, max2;
max(s, 4, &max1, &max2);
printf("%d %d\n", max1, max2);
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment