:param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending Examples: >>> sort([4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12]) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56
(array: list)
| 135 | |
| 136 | |
| 137 | def sort(array: list) -> list: |
| 138 | """ |
| 139 | :param collection: some mutable ordered collection with heterogeneous |
| 140 | comparable items inside |
| 141 | :return: the same collection ordered by ascending |
| 142 | |
| 143 | Examples: |
| 144 | >>> sort([4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12]) |
| 145 | [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] |
| 146 | >>> sort([-1, -5, -3, -13, -44]) |
| 147 | [-44, -13, -5, -3, -1] |
| 148 | >>> sort([]) |
| 149 | [] |
| 150 | >>> sort([5]) |
| 151 | [5] |
| 152 | >>> sort([-3, 0, -7, 6, 23, -34]) |
| 153 | [-34, -7, -3, 0, 6, 23] |
| 154 | >>> sort([1.7, 1.0, 3.3, 2.1, 0.3 ]) |
| 155 | [0.3, 1.0, 1.7, 2.1, 3.3] |
| 156 | >>> sort(['d', 'a', 'b', 'e', 'c']) |
| 157 | ['a', 'b', 'c', 'd', 'e'] |
| 158 | """ |
| 159 | if len(array) == 0: |
| 160 | return array |
| 161 | max_depth = 2 * math.ceil(math.log2(len(array))) |
| 162 | size_threshold = 16 |
| 163 | return intro_sort(array, 0, len(array), size_threshold, max_depth) |
| 164 | |
| 165 | |
| 166 | def intro_sort( |
no test coverage detected