n | from typing import List, Protocol, cast, Any | n | from typing import MutableSequence, Protocol, 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 = List[Comparable] | t | Sortable = MutableSequence[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 |