Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions sorts/pigeonhole_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
# Algorithm for the pigeonhole sorting


def pigeonhole_sort(a) -> None:
def pigeonhole_sort(a: list[int]) -> None:
"""
Sort a list of integers destructively using pigeonhole sort.

>>> a = [8, 3, 2, 7, 4, 6, 8]
>>> b = sorted(a) # a nondestructive sort
>>> pigeonhole_sort(a) # a destructive sort
>>> a == b
True

>>> pigeonhole_sort([])
>>> a = [-4, -1, -9, 0, 5, 2]
>>> pigeonhole_sort(a)
>>> a
[-9, -4, -1, 0, 2, 5]

>>> a = []
>>> pigeonhole_sort(a)
>>> a
[]
"""
if not a:
return
Expand Down
Loading