Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement