Advertisement
allekco

lab1 (version 1.3)

Oct 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <conio.h>
  4. #include <cstdlib>
  5. using namespace std;
  6. #define N 10
  7.  
  8. int randomazer (int min, int max) {
  9. float random;
  10. random = rand();
  11. random = (random / RAND_MAX) * (max - min) + min;
  12. return((int)random);
  13. }
  14.  
  15.  
  16. void vstavki(int* A) {
  17. int j, i, ii;
  18. for (j = 0; j <= N; j++) {
  19. i = 1;
  20. while (i < N) {
  21. if (A[i] >= A[i - 1]) {
  22. i++;
  23. }
  24. else {
  25. while (A[i] < A[i - 1]) {
  26. ii = A[i - 1];
  27. A[i - 1] = A[i];
  28. A[i] = ii;
  29. i--;
  30. }
  31. i = N;
  32. }
  33. }
  34. }
  35. }
  36.  
  37. void input_console (int* A) {
  38. int i;
  39. if (N < 100) {
  40. for (i = 0; i < N; i++) {
  41. cout << A[i] << " ";
  42. }
  43. cout << "\n";
  44. }
  45. }
  46.  
  47.  
  48. int main() {
  49. int key1, key2;
  50. int i;
  51. int A[N];
  52. int B[N]; //because we change array A in 1 sort
  53. cout << "Please input 0 if you want input numbers by yourself, and smth else number if not \n";
  54. cin >> key1;
  55. if (key1 == 0) {
  56. cout << "input numbers: ";
  57. for (i = 0; i < N; i++) {
  58. cin >> A[i];
  59. B[i] = A[i];
  60. }
  61. } else {
  62. for (i = 0; i < N; i++) {
  63. A[i] = randomazer(1, 10);
  64. B[i] = A[i];
  65. }
  66. }
  67. input_console(A);
  68. int marker = 1;
  69. while (marker) {
  70. cout << "Which algoritm do you want?\n";
  71. cout << "1.Insertion sorting\n";
  72. cout << "2.Pyramidal sorting\n";
  73. cout << "0.Exit\n";
  74. cout << "Please choose number: ";
  75. cin >> key2;
  76. clock_t start = clock();
  77. if (key2 == 0) {
  78. marker = 0;
  79. }
  80. if (key2 == 1) {
  81. vstavki(A);
  82. }
  83. else {
  84.  
  85. }
  86. if (marker != 0){
  87. clock_t end = clock();
  88. double total_time = (double(end) - double(start)) / CLOCKS_PER_SEC;
  89. input_console(A);
  90. cout << "Time of work: ";
  91. cout << total_time << "\n";
  92. }
  93. }
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement