| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "nikitin_a_buble_sort/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "nikitin_a_buble_sort/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace nikitin_a_buble_sort { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 162 times.
✗ Branch 2 not taken.
|
162 | NikitinABubleSortSEQ::NikitinABubleSortSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 |
1/2✓ Branch 1 taken 162 times.
✗ Branch 2 not taken.
|
162 | GetInput() = in; // Копируем входной вектор |
| 14 | GetOutput() = {}; // Инициализируем выходной вектор как пустой | ||
| 15 | 162 | } | |
| 16 | |||
| 17 | 162 | bool NikitinABubleSortSEQ::ValidationImpl() { | |
| 18 | 162 | return true; | |
| 19 | } | ||
| 20 | |||
| 21 | 162 | bool NikitinABubleSortSEQ::PreProcessingImpl() { | |
| 22 | 162 | return true; | |
| 23 | } | ||
| 24 | |||
| 25 | 162 | bool NikitinABubleSortSEQ::RunImpl() { | |
| 26 | const std::vector<double> &input_arr = GetInput(); | ||
| 27 | 162 | std::vector<double> arr = input_arr; // Копируем входные данные во временный вектор | |
| 28 | size_t n = arr.size(); | ||
| 29 | |||
| 30 | // Обработка пустого массива | ||
| 31 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 154 times.
|
162 | if (input_arr.empty()) { |
| 32 | GetOutput() = {}; | ||
| 33 | return true; | ||
| 34 | } | ||
| 35 | |||
| 36 | // Стандартная пузырьковая сортировка | ||
| 37 |
2/2✓ Branch 0 taken 13434 times.
✓ Branch 1 taken 154 times.
|
13588 | for (size_t i = 0; i < n - 1; ++i) { |
| 38 |
2/2✓ Branch 0 taken 5036026 times.
✓ Branch 1 taken 13434 times.
|
5049460 | for (size_t j = 0; j < n - i - 1; ++j) { |
| 39 |
2/2✓ Branch 0 taken 2518408 times.
✓ Branch 1 taken 2517618 times.
|
5036026 | if (arr[j] > arr[j + 1]) { |
| 40 | // Обмен элементов | ||
| 41 | std::swap(arr[j], arr[j + 1]); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | // Записываем отсортированный результат в GetOutput | ||
| 47 |
1/2✓ Branch 1 taken 154 times.
✗ Branch 2 not taken.
|
154 | GetOutput() = arr; |
| 48 | |||
| 49 | return true; | ||
| 50 | } | ||
| 51 | |||
| 52 | 162 | bool NikitinABubleSortSEQ::PostProcessingImpl() { | |
| 53 | // Проверяем, что массив отсортирован по возрастанию | ||
| 54 | const std::vector<double> &arr = GetOutput(); | ||
| 55 |
2/2✓ Branch 0 taken 13434 times.
✓ Branch 1 taken 162 times.
|
13596 | for (size_t i = 1; i < arr.size(); ++i) { |
| 56 |
1/2✓ Branch 0 taken 13434 times.
✗ Branch 1 not taken.
|
13434 | if (arr[i - 1] > arr[i]) { |
| 57 | return false; // Массив не отсортирован | ||
| 58 | } | ||
| 59 | } | ||
| 60 | return true; | ||
| 61 | } | ||
| 62 | |||
| 63 | } // namespace nikitin_a_buble_sort | ||
| 64 |