fork(5) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int arr[] = {3, 2, 6, 4};
  5.  
  6. int compare (const void * a, const void * b) {
  7. int diff = arr[*(int*)a] - arr[*(int*)b];
  8. return diff;
  9. }
  10.  
  11. int main(void) {
  12. int perm[4], i;
  13.  
  14. for (i = 0 ; i != 4 ; i++) {
  15. perm[i] = i ;
  16. }
  17. qsort (perm, 4, sizeof(int), compare);
  18.  
  19. for (i = 0 ; i != 4 ; i++) {
  20. printf("%d ", perm[i] + 1);
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
2 1 4 3