Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- int prqka_selekciq();
- int prqko_vmukvane();
- int bubble_method();
- int main()
- {
- prqka_selekciq();
- prqko_vmukvane();
- bubble_method();
- }
- int prqka_selekciq()
- {
- int array[100000], n, c, d, position, swap, rand();
- double duration;
- clock_t start_t, end_t;
- printf("Straight selection\n");
- printf("Enter number of elements\n");
- scanf("%d", &n);
- for ( c = 0 ; c < n ; c++ )
- array[c] = rand();
- start_t = clock();
- for ( c = 0 ; c < ( n - 1 ) ; c++ )
- {
- position = c;
- for ( d = c + 1 ; d < n ; d++ )
- {
- if ( array[position] > array[d] )
- position = d;
- }
- if ( position != c )
- {
- swap = array[c];
- array[c] = array[position];
- array[position] = swap;
- }
- }
- end_t = clock();
- duration = (double) (end_t - start_t) / CLOCKS_PER_SEC;
- printf("Duration of straight selection: %lf\n", duration);
- return 0;
- }
- int prqko_vmukvane()
- {
- int n, array[100000], t, c, d, rand();
- double duration;
- clock_t start_t, end_t, total_t;
- printf("straight insert\n");
- printf("Enter number of elements\n");
- scanf("%d", &n);
- for (c = 0; c < n; c++)
- {
- array[c] = rand();
- }
- start_t = clock();
- for (c = 1 ; c <= n - 1; c++)
- {
- d = c;
- while ( d > 0 && array[d] < array[d-1])
- {
- t = array[d];
- array[d] = array[d-1];
- array[d-1] = t;
- d--;
- }
- }
- end_t = clock();
- duration = (double) (end_t - start_t) / CLOCKS_PER_SEC;
- printf("The duration of straight insert is %lf\n", duration);
- return 0;
- }
- int bubble_method()
- {
- int array[100000], n, c, d, swap, duration, rand();
- clock_t start_t, end_t, total_t;
- printf("Bubble method\n");
- printf("Enter number of elements\n");
- scanf("%d", &n);
- for (c = 0; c < n; c++)
- array[c] = rand();
- start_t = clock();
- for (c = 0 ; c < ( n - 1 ); c++)
- {
- for (d = 0 ; d < n - c - 1; d++)
- {
- if (array[d] > array[d+1])
- {
- swap = array[d];
- array[d] = array[d+1];
- array[d+1] = swap;
- }
- }
- }
- end_t = clock();
- duration = (double) (end_t - start_t) / CLOCKS_PER_SEC;
- printf("Duration of bubble method is %f", duration);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement