Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int sort(const void *first_element, const void *second_element){
- if (abs(*(int *)first_element) < abs(*(int *)second_element)){
- return 1;
- }
- if (abs(*(int *)first_element) > abs(*(int *)second_element)){
- return -1;
- }
- return 0;
- }
- int main(){
- const int amount_of_elements = 1000;
- int array[amount_of_elements];
- time_t start, end;
- for (int i = 0; i < amount_of_elements; i++){
- scanf("%d", &array[i]);
- }
- start = time(NULL);
- qsort(array, amount_of_elements, sizeof(int), sort);
- end = time(NULL);
- for (int i = 0; i < amount_of_elements; i++){
- printf("%d ", array[i]);
- }
- printf("\n%f", difftime(end, start));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement