runnig

indexes of sorted array

Mar 15th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. int cmp(const void* a, const void *b) { return (*(const int*)a)-(*(const int*)b); }
  4.  
  5. int main()
  6. {
  7.     const int N = 4;
  8.     int i;
  9.     int input[] = { 4, 3, 2, 1 };
  10.  
  11.     int aux[2*N];
  12.     for(i = 0; i < N; ++i) { aux[2*i] = input[i]; aux[2*i+1] = i; }
  13.     qsort(aux, N, sizeof(int)*2, cmp);
  14.     for(i = 0; i < N; ++i) { printf("%d ", aux[2*i + 1]); }
  15.     return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment