sorts.odd_even_sort¶
Odd even sort implementation.
https://en.wikipedia.org/wiki/Odd%E2%80%93even_sort
Attributes¶
Classes¶
Base class for protocol classes. |
Functions¶
|
Sort input with odd even sort. |
Module Contents¶
- class sorts.odd_even_sort.Comparable¶
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto[T](Protocol): def meth(self) -> T: ...
- __gt__(other: Any, /) bool¶
- sorts.odd_even_sort.odd_even_sort[T: Comparable](collection: collections.abc.MutableSequence[T]) collections.abc.MutableSequence[T]¶
Sort input with odd even sort.
This algorithm uses the same idea of bubblesort, but by first dividing in two phase (odd and even). Originally developed for use on parallel processors with local interconnections. :param collection: mutable ordered sequence of elements :return: same collection in ascending order Examples: >>> odd_even_sort([5 , 4 ,3 ,2 ,1]) [1, 2, 3, 4, 5] >>> odd_even_sort([]) [] >>> odd_even_sort([-10 ,-1 ,10 ,2]) [-10, -1, 2, 10] >>> odd_even_sort([1 ,2 ,3 ,4]) [1, 2, 3, 4] >>> odd_even_sort([“c”,”a”,”b”]) [‘a’, ‘b’, ‘c’] >>> odd_even_sort([2.5, -1, 0.0]) [-1, 0.0, 2.5] >>> odd_even_sort([1,”a”]) Traceback (most recent call last):
…
TypeError: ‘>’ not supported between instances of ‘int’ and ‘str’
- sorts.odd_even_sort.input_list¶