allekco

lab1 (version 1.1)

Oct 17th, 2019
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. for (i = 0; i < N; i++) {
  40. cout << A[i] << " ";
  41. }
  42. cout << "\n";
  43. }
  44.  
  45.  
  46. int main() {
  47. float start_time, end_time, total_time;
  48. int key1, key2;
  49. int i;
  50. int A[N];
  51. cout << "Please input 0 if you want input numbers by yourself, and smth else number if not \n";
  52. cin >> key1;
  53. if (key1 == 0) {
  54. cout << "input numbers: ";
  55. for (i = 0; i < N; i++) {
  56. cin >> A[i];
  57. }
  58. } else {
  59. for (i = 0; i < N; i++) {
  60. A[i] = randomazer(1, 10);
  61. }
  62. }
  63. cout << "It's your massiv:\n";
  64. input_console(A);
  65. cout << "Which algoritm do you want?\n";
  66. cout << "1.Insertion sorting\n";
  67. cout << "2.Pyramidal sorting\n";
  68. cout << "Please choose number: ";
  69. cin >> key2;
  70. start_time = clock();
  71. if (key2 == 1) {
  72. vstavki(A);
  73. input_console(A);
  74. }
  75. else {
  76.  
  77. }
  78. end_time = clock();
  79. total_time = end_time - start_time;
  80. cout << "Time of work: ";
  81. cout << total_time;
  82. _getch();
  83. return 0;
  84. }
RAW Paste Data