sorts.comb_sort

This is pure Python implementation of comb sort algorithm. Comb sort is a relatively simple sorting algorithm originally designed by Wlodzimierz Dobosiewicz in 1980. It was rediscovered by Stephen Lacey and Richard Box in 1991. Comb sort improves on bubble sort algorithm. In bubble sort, distance (or gap) between two compared elements is always one. Comb sort improvement is that gap can be much more than 1, in order to prevent slowing down by small values at the end of a list.

More info on: https://en.wikipedia.org/wiki/Comb_sort

For doctests run following command: python -m doctest -v comb_sort.py or python3 -m doctest -v comb_sort.py

For manual testing run: python comb_sort.py

Attributes

user_input

Classes

Comparable

Base class for protocol classes.

Functions

comb_sort(→ list[T])

Pure implementation of comb sort algorithm in Python

Module Contents

class sorts.comb_sort.Comparable

Bases: Protocol

Base 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
sorts.comb_sort.comb_sort[T: Comparable](data: list[T]) list[T]

Pure implementation of comb sort algorithm in Python :param data: mutable collection with comparable items :return: the same collection in ascending order Examples: >>> comb_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> comb_sort([]) [] >>> comb_sort([99, 45, -7, 8, 2, 0, -15, 3]) [-15, -7, 0, 2, 3, 8, 45, 99] >>> comb_sort([2, 0, 3, 4, 5, 6, 1]) [0, 1, 2, 3, 4, 5, 6] >>> comb_sort([“c”, “a”, “b”]) [‘a’, ‘b’, ‘c’] >>> comb_sort([2.5, -1, 0.0]) [-1, 0.0, 2.5] >>> comb_sort([1, “a”]) Traceback (most recent call last): … TypeError: ‘<’ not supported between instances of ‘str’ and ‘int’

sorts.comb_sort.user_input