Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define N 1000
- int cmp(const void *a1, const void *a2){
- int *n1 = (int *) a1;
- int *n2 = (int *) a2;
- if(abs(*n1) < abs(*n2))
- return 1;
- if(abs(*n1) > abs(*n2))
- return -1;
- return 0;
- }
- int main() {
- clock_t first_timestamp, second_timestamp;
- int arr[N];
- for(int i = 0; i < N; i++){
- scanf("%d", &arr[i]);
- }
- first_timestamp = clock();
- qsort(arr, N, sizeof(int), cmp);
- second_timestamp = clock() - first_timestamp;
- for(int i = 0; i < N; i++){
- printf("%d ", arr[i]);
- }
- printf("\n");
- printf("%f", (double)second_timestamp / CLOCKS_PER_SEC);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement