sorts.tree_sort¶
Tree_sort algorithm. Build a Binary Search Tree and then iterate thru it to get a sorted list.
Classes¶
Base class for protocol classes. |
|
Functions¶
|
Module Contents¶
- class sorts.tree_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: ...
- __lt__(other: Any, /) bool¶
- class sorts.tree_sort.Node[T: Comparable]¶
-
- __len__() int¶
- sorts.tree_sort.tree_sort[T: Comparable](arr: collections.abc.Iterable[T]) tuple[T, ...]¶
>>> tree_sort([]) () >>> tree_sort((1,)) (1,) >>> tree_sort((1, 2)) (1, 2) >>> tree_sort([5, 2, 7]) (2, 5, 7) >>> tree_sort((5, -4, 9, 2, 7)) (-4, 2, 5, 7, 9) >>> tree_sort([5, 6, 1, -1, 4, 37, 2, 7]) (-1, 1, 2, 4, 5, 6, 7, 37) >>> tree_sort(range(10, -10, -1)) == tuple(sorted(range(10, -10, -1))) True >>> tree_sort(["c", "a", "b"]) ('a', 'b', 'c') >>> tree_sort([2.5, -1, 0.0]) (-1, 0.0, 2.5) >>> tree_sort([3, 1, 3, 2, 1]) (1, 1, 2, 3, 3) >>> tree_sort([2, 2, 2]) (2, 2, 2) >>> tree_sort([1, "a"]) Traceback (most recent call last): ... TypeError: '<' not supported between instances of 'str' and 'int'