SHARE
TWEET

lab1 (version 1.2)

allekco Oct 17th, 2019 85 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.     int B[N]; //because we change array A in 1 sort
  52.     cout << "Please input 0 if you want input numbers by yourself, and smth else number if not \n";
  53.     cin >> key1;
  54.     if (key1 == 0) {
  55.         cout << "input numbers: ";
  56.         for (i = 0; i < N; i++) {
  57.             cin >> A[i];
  58.             B[i] = A[i];
  59.         }
  60.     } else {
  61.         for (i = 0; i < N; i++) {
  62.             A[i] = randomazer(1, 10);
  63.             B[i] = A[i];
  64.         }
  65.     }
  66.     //cout << "It's your massiv:\n";
  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.         start_time = clock();
  77.         if (key2 == 0) {
  78.             marker = 0;
  79.         }
  80.         if (key2 == 1) {
  81.             vstavki(A);
  82.             //input_console(A);
  83.         }
  84.         else {
  85.  
  86.         }
  87.         end_time = clock();
  88.         total_time = end_time - start_time;
  89.         cout << "Time of work: ";
  90.         cout << total_time << "\n";
  91.     }
  92.     _getch();
  93.     return 0;
  94. }
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