| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "volkov_a_odd_even_transposition/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <utility> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "volkov_a_odd_even_transposition/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace volkov_a_odd_even_transposition { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | OddEvenSortSeq::OddEvenSortSeq(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | GetInput() = in; |
| 15 | 48 | } | |
| 16 | |||
| 17 | 48 | bool OddEvenSortSeq::ValidationImpl() { | |
| 18 | 48 | return GetOutput().empty(); | |
| 19 | } | ||
| 20 | |||
| 21 | 48 | bool OddEvenSortSeq::PreProcessingImpl() { | |
| 22 | 48 | GetOutput() = GetInput(); | |
| 23 | 48 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 8 times.
|
48 | bool OddEvenSortSeq::RunImpl() { |
| 27 | auto &arr = GetOutput(); | ||
| 28 | size_t n = arr.size(); | ||
| 29 | |||
| 30 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 8 times.
|
48 | if (n < 2) { |
| 31 | return true; | ||
| 32 | } | ||
| 33 | |||
| 34 | bool is_sorted = false; | ||
| 35 | |||
| 36 |
2/2✓ Branch 0 taken 1351 times.
✓ Branch 1 taken 40 times.
|
1391 | while (!is_sorted) { |
| 37 | is_sorted = true; | ||
| 38 | |||
| 39 | // Нечетная фаза | ||
| 40 |
2/2✓ Branch 0 taken 61524 times.
✓ Branch 1 taken 1351 times.
|
62875 | for (size_t i = 1; i < n - 1; i += 2) { |
| 41 |
2/2✓ Branch 0 taken 40884 times.
✓ Branch 1 taken 20640 times.
|
61524 | if (arr[i] > arr[i + 1]) { |
| 42 | std::swap(arr[i], arr[i + 1]); | ||
| 43 | is_sorted = false; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | // Четная фаза | ||
| 48 |
2/2✓ Branch 0 taken 62875 times.
✓ Branch 1 taken 1351 times.
|
64226 | for (size_t i = 0; i < n - 1; i += 2) { |
| 49 |
2/2✓ Branch 0 taken 41266 times.
✓ Branch 1 taken 21609 times.
|
62875 | if (arr[i] > arr[i + 1]) { |
| 50 | std::swap(arr[i], arr[i + 1]); | ||
| 51 | is_sorted = false; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | return true; | ||
| 57 | } | ||
| 58 | |||
| 59 | 48 | bool OddEvenSortSeq::PostProcessingImpl() { | |
| 60 | 48 | return true; | |
| 61 | } | ||
| 62 | |||
| 63 | } // namespace volkov_a_odd_even_transposition | ||
| 64 |