Skip to content

Instantly share code, notes, and snippets.

@CindyLinz
Last active March 23, 2016 09:22
Show Gist options
  • Save CindyLinz/c88ecdf54794c1f02ab5 to your computer and use it in GitHub Desktop.
Save CindyLinz/c88ecdf54794c1f02ab5 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(){
int value[] = {2,5,4,3,8,7,9,1,10,6};
int index[] = {0,1,2,3,4,5,6,7,8,9};
int cmp(const void * a, const void * b){
return value[*(int*)a] - value[*(int*)b];
}
qsort(index, 10, sizeof(int), cmp);
for(int i=0; i<10; ++i)
printf("%d ", value[index[i]]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment