SHARE
TWEET

Untitled

a guest Dec 14th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int sort(const void *first_element, const void *second_element){
  6.     if (abs(*(int *)first_element) < abs(*(int *)second_element)){
  7.         return 1;
  8.     }
  9.     if (abs(*(int *)first_element) > abs(*(int *)second_element)){
  10.         return -1;
  11.     }
  12.     return 0;
  13. }
  14. int main(){
  15.     const int amount_of_elements = 1000;
  16.     int array[amount_of_elements];
  17.     time_t start, end;
  18.     for (int i = 0; i < amount_of_elements; i++){
  19.         scanf("%d", &array[i]);
  20.     }
  21.     start = time(NULL);
  22.     qsort(array, amount_of_elements, sizeof(int), sort);
  23.     end = time(NULL);
  24.     for (int i = 0; i < amount_of_elements; i++){
  25.         printf("%d ", array[i]);
  26.     }
  27.     printf("\n%f", difftime(end, start));
  28.     return 0;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top