• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Dec 12th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2. #include <stdlib.h>
3.
4. #include <time.h>
5.
6. #define SIZE 10000
7. // Функция быстрой сортировки
8. void quickSort(int *numbers, int left, int right)
9. {
10.     int pivot;
11.     int l_hold = left;
12.     int r_hold = right;
13.     pivot = numbers[left];
14.
15.
16.     while (left < right)
17.     {
18.         while ((numbers[right] >= pivot) && (left < right))
19.             right--;
20.         if (left != right)
21.         {
22.             numbers[left] = numbers[right];
23.             left++;
24.         }
25.         while ((numbers[left] <= pivot) && (left < right))
26.             left++;
27.         if (left != right)
28.         {
29.             numbers[right] = numbers[left];
30.             right--;
31.         }
32.     }
33.     numbers[left] = pivot;
34.     pivot = left;
35.     left = l_hold;
36.     right = r_hold;
37.     if (left < pivot)
38.         quickSort(numbers, left, pivot - 1);
39.     if (right > pivot)
40.         quickSort(numbers, pivot + 1, right);
41. }
42.
43.
44. int main()
45. {
46.     time_t t0 = time(0);
47.
48.     int a[SIZE];
49.     for (int i = 0; i < SIZE; i++)
50.         a[i] = rand() % 201 - 100;
51.     for (int i = 0; i < SIZE; i++)
52.         printf("%4d ", a[i]);
53.     printf("\n");
54.     quickSort(a, 0, SIZE - 1);
55.
56.
57.     time_t t1 = time(0);
58.
59.     for (int i = 0; i < SIZE; i++)
60.         printf("%4d ", a[i]);
61.     printf("\n");
62.
63.
64.     //time_t t1 = time(0);
65.     double time_in_seconds = difftime(t1, t0);
66.
67.     double timer = t1 - t0;
68.
69.
70.     int value = (int)timer ;
71.     printf("Time of programma : ");
72.     printf("%f", time_in_seconds);
73.
74.     getchar();
75.     return 0;
76.
77. }
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.
Not a member of Pastebin yet?