Skip to content

Commit 99f3a0e

Browse files
Arya-Haripre-commit-ci[bot]cclauss
authored
adding-docstrings (TheAlgorithms#11114)
* adding-docstrings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update intro_sort.py * Update intro_sort.py * Remove blank lines --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent b072ba6 commit 99f3a0e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: sorts/intro_sort.py

+27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ def insertion_sort(array: list, start: int = 0, end: int = 0) -> list:
1111
>>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12]
1212
>>> insertion_sort(array, 0, len(array))
1313
[1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79]
14+
>>> array = [21, 15, 11, 45, -2, -11, 46]
15+
>>> insertion_sort(array, 0, len(array))
16+
[-11, -2, 11, 15, 21, 45, 46]
17+
>>> array = [-2, 0, 89, 11, 48, 79, 12]
18+
>>> insertion_sort(array, 0, len(array))
19+
[-2, 0, 11, 12, 48, 79, 89]
20+
>>> array = ['a', 'z', 'd', 'p', 'v', 'l', 'o', 'o']
21+
>>> insertion_sort(array, 0, len(array))
22+
['a', 'd', 'l', 'o', 'o', 'p', 'v', 'z']
23+
>>> array = [73.568, 73.56, -45.03, 1.7, 0, 89.45]
24+
>>> insertion_sort(array, 0, len(array))
25+
[-45.03, 0, 1.7, 73.56, 73.568, 89.45]
1426
"""
1527
end = end or len(array)
1628
for i in range(start, end):
@@ -47,6 +59,12 @@ def heap_sort(array: list) -> list:
4759
"""
4860
>>> heap_sort([4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12])
4961
[1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79]
62+
>>> heap_sort([-2, -11, 0, 0, 0, 87, 45, -69, 78, 12, 10, 103, 89, 52])
63+
[-69, -11, -2, 0, 0, 0, 10, 12, 45, 52, 78, 87, 89, 103]
64+
>>> heap_sort(['b', 'd', 'e', 'f', 'g', 'p', 'x', 'z', 'b', 's', 'e', 'u', 'v'])
65+
['b', 'b', 'd', 'e', 'e', 'f', 'g', 'p', 's', 'u', 'v', 'x', 'z']
66+
>>> heap_sort([6.2, -45.54, 8465.20, 758.56, -457.0, 0, 1, 2.879, 1.7, 11.7])
67+
[-457.0, -45.54, 0, 1, 1.7, 2.879, 6.2, 11.7, 758.56, 8465.2]
5068
"""
5169
n = len(array)
5270

@@ -91,6 +109,15 @@ def partition(array: list, low: int, high: int, pivot: int) -> int:
91109
>>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12]
92110
>>> partition(array, 0, len(array), 12)
93111
8
112+
>>> array = [21, 15, 11, 45, -2, -11, 46]
113+
>>> partition(array, 0, len(array), 15)
114+
3
115+
>>> array = ['a', 'z', 'd', 'p', 'v', 'l', 'o', 'o']
116+
>>> partition(array, 0, len(array), 'p')
117+
5
118+
>>> array = [6.2, -45.54, 8465.20, 758.56, -457.0, 0, 1, 2.879, 1.7, 11.7]
119+
>>> partition(array, 0, len(array), 2.879)
120+
6
94121
"""
95122
i = low
96123
j = high

0 commit comments

Comments
 (0)