Advertisement
Petro_zzz

quickSortR

Dec 15th, 2023
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include "Header.h"
  4. #include <thread>
  5. #include <string>
  6.  
  7. #include <windows.h>
  8.  
  9. #define SQR(Y) (Y)*(Y)
  10.  
  11. #define IS_DEBUG
  12.  
  13. const int week_end = 7;
  14.  
  15. using namespace std;
  16.  
  17. template <class T>
  18. void quickSortR(T a[], long N) {
  19.     // На входе - массив a[],
  20.     // a[N] - его последний элемент.
  21.     // поставить указатели на исходные места
  22.     long i = 0, j = N;
  23.     T temp, p;
  24.     p = a[N / 2]; // центральный элемент
  25.     // процедура разделения
  26.     do {
  27.         while (a[i] < p) i++;
  28.         while (a[j] > p) j--;
  29.         if (i <= j) {
  30.             temp = a[i];
  31.             a[i] = a[j];
  32.             a[j] = temp;
  33.             i++;
  34.             j--;
  35.         }
  36.     } while (i <= j);
  37.     /*
  38.     рекурсивные вызовы, если есть,
  39.     что сортировать
  40.     */
  41.     if (j > 0) quickSortR(a, j);
  42.     if (N > i) quickSortR(a + i, N - i);
  43. }
  44.  
  45. void test_sort() {
  46.     srand(time(NULL));
  47.     const long SIZE = 10;
  48.     int ar[SIZE];
  49.     // до сортировки
  50.     for (int i = 0; i < SIZE; i++) {
  51.         ar[i] = rand() % 100;
  52.         cout << ar[i] << "\t";
  53.     }
  54.     cout << "\n\n";
  55.     /*
  56.     const long SIZE = 10;
  57.     int ar[SIZE]{ 3,4,5,2,5,6,1,2,9,10 };
  58.     */
  59.     quickSortR(ar, SIZE - 1);
  60.     // после сортировки
  61.     for (int i = 0; i < SIZE; i++) {
  62.         cout << ar[i] << "\t";
  63.     }
  64.     cout << "\n\n";
  65. }
  66.  
  67. void test_macros() {
  68. #ifdef IS_DEBUG
  69.     cout << "This is DEBUG";
  70. #else
  71.     cout << "This is RELEASE";
  72. #endif // !IS_DEBUG == 0       
  73.     cout << SQR(2 + 3) << endl;
  74. }
  75.  
  76. struct ManID {
  77.     int age = 0;
  78.     std::string name = "Jon Dou";
  79.     int pasport_id[6]{7,4,7,7,5,7};
  80.  
  81.     void show() {
  82.         cout << name << endl;
  83.     }
  84. };
  85.  
  86. void show_man(ManID &man) {
  87.     cout << man.age << " " << man.name << endl;
  88. }
  89.  
  90. void test_struct() {
  91.    
  92.     enum MODE {ON, OFF};
  93.     MODE reg1 = MODE::ON;
  94.     MODE reg2 = MODE::OFF;
  95.  
  96.     enum {LEFT, RIGHT, MIDLE} reg3 = LEFT;
  97.  
  98.     ManID first;
  99.     first.age = 17;
  100.     first.name = "Petya";
  101.  
  102.     //cout << first << endl;
  103.     cout << first.age << " " << first.name << endl;
  104.  
  105.     ManID second{32, "Masha"};
  106.     cout << second.age << " " << second.name << endl;
  107.  
  108.     show_man(first);
  109.     show_man(second);
  110.     cout << first.pasport_id[3] << endl;
  111.     ManID mans[100];
  112.     std::string str1 = "Hi everybody";
  113.     cout << str1.length() << endl;
  114.     mans[20].show();
  115. }
  116.  
  117. struct Wear {
  118.     std::string name;
  119.     int hp;
  120.     int armor;
  121.     int damage;
  122. };
  123.  
  124. struct Warior {
  125.     std::string name = "Y";
  126.     int hp = 100;
  127.     int armor = 0;
  128.     int damage = 0;
  129.     Wear wear[10];
  130. };
  131.  
  132. void game() {
  133.     Warior person1, person2;
  134.    
  135.     cout << "Pl1: Enter name: ";
  136.     getline(cin, person1.name);
  137.  
  138.     cout << "Pl2: Enter name: ";
  139.     getline(cin, person2.name);
  140.  
  141.     person1.wear[0].name = "Sword";
  142.     person1.wear[0].damage = 10;
  143.  
  144.     person2.wear[0].name = "Foots";
  145.     person2.wear[0].armor = 3;
  146.  
  147.  
  148.  
  149.  
  150. }
  151.  
  152. int main() {
  153.    
  154.     for (int k = 0; k < 1000; k++) {       
  155.         cout << k;
  156.         Sleep(0.25);
  157.         system("cls");
  158.     }
  159.  
  160.     return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement