SHARE
TWEET

lab1 (version 1)

allekco Oct 17th, 2019 77 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. using namespace std;
  5.  
  6. #define N 10
  7.  
  8. int randomazer (int max, int min) {
  9.     float random;
  10.     random = rand();
  11.     random = (random / RAND_MAX) * (max - min) + min;
  12.     return((int)random);
  13. }
  14.  
  15. void vstavki(int* A) {
  16.     int j, i, ii;
  17.     for (j = 0; j <= N; j++) {
  18.         i = 1;
  19.         while (i < N) {
  20.             if (A[i] >= A[i - 1]) {
  21.                 i++;
  22.             }
  23.             else {
  24.                 while (A[i] < A[i - 1]) {
  25.                     ii = A[i - 1];
  26.                     A[i - 1] = A[i];
  27.                     A[i] = ii;
  28.                     i--;
  29.                 }
  30.                 i = N;
  31.             }
  32.         }
  33.     }
  34. }
  35.  
  36. void input_console (int* A) {
  37.     int i;
  38.     for (i = 0; i < N; i++) {
  39.         cout << A[i] << " ";
  40.     }
  41.     cout << "\n";
  42. }
  43.  
  44.  
  45. int main() {
  46.     int start_time, end_time, total_time;
  47.     int key1, key2;
  48.     int i;
  49.     int A[N];
  50.     cout << "Please input 0 if you want input numbers by yourself, and smth else number if not \n";
  51.     cin >> key1;
  52.     if (key1 == 0) {
  53.         cout << "input numbers";
  54.         for (i = 0; i < N; i++) {
  55.             cin >> A[i];
  56.         }
  57.     } else {
  58.         for (i = 0; i < key1; i++) {
  59.             A[i] = randomazer(1, 100);
  60.         }
  61.     }
  62.     cout << "It's your massiv:\n";
  63.     input_console(A);
  64.     cout << "Which algoritm do you want?\n";
  65.     cout << "1.Insertion sorting\n";
  66.     cout << "2.Pyramidal sorting\n";
  67.     cout << "Please choose number: ";
  68.     cin >> key2;
  69.     start_time = clock();
  70.     if (key2 == 1) {
  71.         vstavki(A);
  72.         input_console(A);
  73.     }
  74.     else {
  75.  
  76.     }
  77.     end_time = clock();
  78.     total_time = end_time - start_time;
  79.     cout << "Time of work: ";
  80.     cout << total_time;
  81.     _getch();
  82.     return 0;
  83. }
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. OK, I Understand
 
Top