Advertisement
Savelyev_Vyacheslav

ANZH_SORT

May 15th, 2021
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <thread>
  5. #include <ctime>
  6. #include <stdio.h>
  7. #include <cstdlib>
  8. #include <string.h>
  9. using namespace std;
  10.  
  11.  
  12. class GETtime
  13. {
  14.  
  15. public:
  16. int sec_t;
  17. int MSCostatok;
  18. int Stepss;
  19.  
  20. int min_t;
  21. int milisecTotal;//
  22.  
  23. void strtT()
  24. {
  25. tStart = std::chrono::high_resolution_clock::now();
  26. chrono::duration<float> strtT = tStart - tStart;
  27. cout << "strtT: " << strtT.count() << endl;
  28. }
  29. void endT()
  30. {
  31. tEnd = std::chrono::high_resolution_clock::now();
  32. chrono::duration<float> duration = (tEnd - tStart) * 1000;
  33. GETtime::milisecTotal = duration.count();
  34. GETtime::min_t = (duration.count() / 1000 / 60);
  35. GETtime::sec_t = int(duration.count() / 1000) % 60;
  36. GETtime::MSCostatok = int(duration.count()) - min_t * 60 * 1000 - sec_t * 1000;
  37. chrono::duration<float> strtT = tStart - tStart;
  38. cout << "Vivid d milisec: " << duration.count() << endl;//
  39. cout << "minut: " << GETtime::min_t << " sekund: " << GETtime::sec_t << " milisekund " << GETtime::MSCostatok << endl;
  40. }
  41. void print_Iteration() {
  42. cout << " Секунд за 1 итерацию: " << GETtime::milisecTotal / Stepss << endl;
  43.  
  44. }
  45. private:
  46. std::chrono::time_point<std::chrono::steady_clock> tStart, tEnd;
  47. };
  48.  
  49.  
  50. int* makeARR(int* arr, int ArrElements) {
  51. int k = 0;
  52. while (k < ArrElements) {
  53. arr[k] = (rand() % 10000) + 1;//
  54. k = k + 1;
  55. }
  56. return arr;
  57. }
  58.  
  59.  
  60.  
  61.  
  62. void sortQuick(int* mas, int fir1, int tail)
  63. {
  64. int mid, count;
  65. int t = fir1, end = tail;
  66. mid = mas[(t + end) / 2];
  67. do
  68. {
  69. while (mas[t] < mid) t++;
  70. while (mas[end] > mid) end--;
  71. if (t <= end)
  72. {
  73. count = mas[t];
  74. mas[t] = mas[end];
  75. mas[end] = count;
  76. t++;
  77. end--;
  78. }
  79. } while (t < end);
  80. if (fir1 < end) sortQuick(mas, fir1, end);
  81. if (t < tail) sortQuick(mas, t, tail);
  82. }
  83. void printMassiv(int* arr3, int n) {
  84. int i = 0;
  85. while (i < n) {
  86.  
  87. cout << "i" << i << " " << arr3[i] << endl;
  88. i = i + 1;
  89. }
  90.  
  91. }
  92. //
  93. //
  94. LPWSTR FormatToWIN32(char in[], wchar_t format[128]) {
  95. mbstowcs(format, in, strlen(in) + 1);
  96. LPWSTR NewFormat = format;
  97. return NewFormat;
  98. }
  99.  
  100.  
  101.  
  102. int main( int argc, char* argv[])
  103. {
  104. GETtime LiveOfFun;
  105. LiveOfFun.strtT();
  106.  
  107.  
  108.  
  109.  
  110. char title[128] = "sortAnzh";
  111.  
  112. if (argc != 3) {
  113. cerr << "Sort - zapustite master\n";
  114. exit(1);
  115. }
  116.  
  117.  
  118. cout << "1" << argv[2] << "\n";
  119. cout << "2" << argv[1] << "\n";
  120. cout << "3" << argv[0] << "\n";
  121.  
  122. sprintf(title + strlen(title), " %s", argv[1]);
  123. sprintf(title + strlen(title), " %s", argv[2]);
  124. wchar_t formarW[128];
  125. LPWSTR pp = FormatToWIN32(title, formarW);
  126. SetConsoleTitle(pp);
  127.  
  128.  
  129. const int ArrElements = 100;
  130. int arr[ArrElements];
  131. int* aRR = makeARR(arr, ArrElements);
  132.  
  133. sortQuick(arr, 0, ArrElements - 1);
  134. printMassiv(arr, ArrElements);
  135.  
  136.  
  137. LiveOfFun.Stepss = ArrElements;
  138. LiveOfFun.endT();
  139. LiveOfFun.print_Iteration();
  140. cout << "sort: выход\n";
  141.  
  142. //system("pause");
  143. Sleep(2000);
  144. return 0;
  145. }
  146.  
  147.  
  148.  
  149. //Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
  150. // Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
  151.  
  152. // Советы по началу работы
  153. // 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
  154. // 2. В окне Team Explorer можно подключиться к системе управления версиями.
  155. // 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
  156. // 4. В окне "Список ошибок" можно просматривать ошибки.
  157. // 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
  158. // 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement