n | from typing import MutableSequence, Protocol, Any | n | from typing import List, Protocol, cast, Any |
| from typing import cast | | |
| | | |
| class Comparable(Protocol): | | class Comparable(Protocol): |
| | | |
| def __lt__(self, other: Any) -> bool: | | def __lt__(self, other: Any) -> bool: |
| ... | | ... |
t | Sortable = MutableSequence[Comparable] | t | Sortable = List[Comparable] |
| | | |
| def bubble(sequence: Sortable) -> Sortable: | | def bubble(sequence: Sortable) -> Sortable: |
| n = len(sequence) | | n = len(sequence) |
| for i in range(n): | | for i in range(n): |
| for j in range(0, n - i - 1): | | for j in range(0, n - i - 1): |
| if sequence[j] > sequence[j + 1]: | | if sequence[j] > sequence[j + 1]: |
| sequence[j], sequence[j + 1] = (sequence[j + 1], sequence[j]) | | sequence[j], sequence[j + 1] = (sequence[j + 1], sequence[j]) |
| return sequence | | return sequence |