Advertisement
maxim_shlyahtin

lb_4

Feb 6th, 2023 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define N 1000
  6.  
  7. int cmp(const void *a1, const void *a2){
  8. int *n1 = (int *) a1;
  9. int *n2 = (int *) a2;
  10. if(abs(*n1) < abs(*n2))
  11. return 1;
  12. if(abs(*n1) > abs(*n2))
  13. return -1;
  14. return 0;
  15. }
  16.  
  17.  
  18. int main() {
  19. clock_t first_timestamp, second_timestamp;
  20. int arr[N];
  21. for(int i = 0; i < N; i++){
  22. scanf("%d", &arr[i]);
  23. }
  24. first_timestamp = clock();
  25. qsort(arr, N, sizeof(int), cmp);
  26. second_timestamp = clock() - first_timestamp;
  27. for(int i = 0; i < N; i++){
  28. printf("%d ", arr[i]);
  29. }
  30. printf("\n");
  31. printf("%f", (double)second_timestamp / CLOCKS_PER_SEC);
  32. return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement