This function first produces a bitonic sequence by recursively sorting its two halves in opposite sorting orders, and then calls bitonic_merge to make them in the same order. >>> arr = [12, 34, 92, -23, 0, -121, -167, 145] >>> bitonic_sort(arr, 0, 8, 1) >>> arr [-167, -
(array: list[int], low: int, length: int, direction: int)
| 63 | |
| 64 | |
| 65 | def bitonic_sort(array: list[int], low: int, length: int, direction: int) -> None: |
| 66 | """ |
| 67 | This function first produces a bitonic sequence by recursively sorting its two |
| 68 | halves in opposite sorting orders, and then calls bitonic_merge to make them in the |
| 69 | same order. |
| 70 | |
| 71 | >>> arr = [12, 34, 92, -23, 0, -121, -167, 145] |
| 72 | >>> bitonic_sort(arr, 0, 8, 1) |
| 73 | >>> arr |
| 74 | [-167, -121, -23, 0, 12, 34, 92, 145] |
| 75 | |
| 76 | >>> bitonic_sort(arr, 0, 8, 0) |
| 77 | >>> arr |
| 78 | [145, 92, 34, 12, 0, -23, -121, -167] |
| 79 | """ |
| 80 | if length > 1: |
| 81 | middle = int(length / 2) |
| 82 | bitonic_sort(array, low, middle, 1) |
| 83 | bitonic_sort(array, low + middle, middle, 0) |
| 84 | bitonic_merge(array, low, length, direction) |
| 85 | |
| 86 | |
| 87 | if __name__ == "__main__": |
no test coverage detected