Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4.  
  5. int prqka_selekciq();
  6. int prqko_vmukvane();
  7. int bubble_method();
  8.  
  9.  
  10. int main()
  11. {
  12. prqka_selekciq();
  13. prqko_vmukvane();
  14. bubble_method();
  15. }
  16. int prqka_selekciq()
  17. {
  18. int array[100000], n, c, d, position, swap, rand();
  19. double duration;
  20. clock_t start_t, end_t;
  21.  
  22. printf("Straight selection\n");
  23. printf("Enter number of elements\n");
  24. scanf("%d", &n);
  25.  
  26.  
  27.  
  28. for ( c = 0 ; c < n ; c++ )
  29. array[c] = rand();
  30.  
  31. start_t = clock();
  32. for ( c = 0 ; c < ( n - 1 ) ; c++ )
  33. {
  34. position = c;
  35.  
  36. for ( d = c + 1 ; d < n ; d++ )
  37. {
  38. if ( array[position] > array[d] )
  39. position = d;
  40. }
  41. if ( position != c )
  42. {
  43. swap = array[c];
  44. array[c] = array[position];
  45. array[position] = swap;
  46. }
  47. }
  48. end_t = clock();
  49. duration = (double) (end_t - start_t) / CLOCKS_PER_SEC;
  50. printf("Duration of straight selection: %lf\n", duration);
  51. return 0;
  52. }
  53.  
  54.  
  55. int prqko_vmukvane()
  56. {
  57. int n, array[100000], t, c, d, rand();
  58. double duration;
  59. clock_t start_t, end_t, total_t;
  60.  
  61. printf("straight insert\n");
  62. printf("Enter number of elements\n");
  63. scanf("%d", &n);
  64.  
  65. for (c = 0; c < n; c++)
  66. {
  67. array[c] = rand();
  68. }
  69. start_t = clock();
  70. for (c = 1 ; c <= n - 1; c++)
  71. {
  72. d = c;
  73. while ( d > 0 && array[d] < array[d-1])
  74. {
  75. t = array[d];
  76. array[d] = array[d-1];
  77. array[d-1] = t;
  78. d--;
  79. }
  80. }
  81. end_t = clock();
  82. duration = (double) (end_t - start_t) / CLOCKS_PER_SEC;
  83. printf("The duration of straight insert is %lf\n", duration);
  84. return 0;
  85. }
  86.  
  87. int bubble_method()
  88. {
  89. int array[100000], n, c, d, swap, duration, rand();
  90. clock_t start_t, end_t, total_t;
  91.  
  92. printf("Bubble method\n");
  93. printf("Enter number of elements\n");
  94. scanf("%d", &n);
  95.  
  96.  
  97. for (c = 0; c < n; c++)
  98. array[c] = rand();
  99. start_t = clock();
  100. for (c = 0 ; c < ( n - 1 ); c++)
  101. {
  102. for (d = 0 ; d < n - c - 1; d++)
  103. {
  104. if (array[d] > array[d+1])
  105. {
  106. swap = array[d];
  107. array[d] = array[d+1];
  108. array[d+1] = swap;
  109. }
  110. }
  111. }
  112. end_t = clock();
  113. duration = (double) (end_t - start_t) / CLOCKS_PER_SEC;
  114. printf("Duration of bubble method is %f", duration);
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement