From 242b08ed1089270055b73fa033c15f0f9607e9c4 Mon Sep 17 00:00:00 2001 From: Arya Hariharan Date: Tue, 31 Oct 2023 10:00:08 +0530 Subject: [PATCH 1/5] adding-docstrings --- sorts/intro_sort.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sorts/intro_sort.py b/sorts/intro_sort.py index 908d2886533a..20ee79c4dc7e 100644 --- a/sorts/intro_sort.py +++ b/sorts/intro_sort.py @@ -11,6 +11,19 @@ def insertion_sort(array: list, start: int = 0, end: int = 0) -> list: >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> insertion_sort(array, 0, len(array)) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] + >>> array = [21, 15, 11, 45, -2, -11, 46] + >>> insertion_sort(array, 0, len(array)) + [-11, -2, 11, 15, 21, 45, 46] + >>> array = [-2, 0, 89, 11, 48, 79, 12] + >>> insertion_sort(array, 0, len(array)) + [-2, 0, 11, 12, 48, 79, 89] + >>> array = ['a', 'z', 'd', 'p', 'v', 'l', 'o', 'o'] + >>> insertion_sort(array, 0, len(array)) + ['a', 'd', 'l', 'o', 'o', 'p', 'v', 'z'] + >>> array = [73.568, 73.56, -45.03, 1.7, 0, 89.45] + >>> insertion_sort(array, 0, len(array)) + [-45.03, 0, 1.7, 73.56, 73.568, 89.45] + """ end = end or len(array) for i in range(start, end): @@ -47,6 +60,13 @@ def heap_sort(array: list) -> list: """ >>> heap_sort([4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12]) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] + >>> heap_sort([-2, -11, 0, 0, 0, 87, 45, -69, 78, 12, 10, 103, 89, 52]) + [-69, -11, -2, 0, 0, 0, 10, 12, 45, 52, 78, 87, 89, 103] + >>> heap_sort(['b', 'd', 'e', 'f', 'g', 'p', 'x', 'z', 'b', 's', 'e' , 'u' , 'v', 'w', 'i', 'm']) + ['b', 'b', 'd', 'e', 'e', 'f', 'g', 'i', 'm', 'p', 's', 'u', 'v', 'w', 'x', 'z'] + >>> heap_sort([6.2, -45.54, 8465.20, 758.56, -457.0, 0, 1, 2.879, 1.7, 11.7]) + [-457.0, -45.54, 0, 1, 1.7, 2.879, 6.2, 11.7, 758.56, 8465.2] + """ n = len(array) @@ -91,6 +111,15 @@ def partition(array: list, low: int, high: int, pivot: int) -> int: >>> array = [4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12] >>> partition(array, 0, len(array), 12) 8 + >>> array = [21, 15, 11, 45, -2, -11, 46] + >>> partition(array, 0, len(array), 15) + 3 + >>> array = ['a', 'z', 'd', 'p', 'v', 'l', 'o', 'o'] + >>> partition(array, 0, len(array), 'p') + 5 + >>> array = [6.2, -45.54, 8465.20, 758.56, -457.0, 0, 1, 2.879, 1.7, 11.7] + >>> partition(array, 0, len(array), 2.879) + 6 """ i = low j = high From d8b8484777348e346f1f0f99860add8f61f2cca8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 04:33:09 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/intro_sort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sorts/intro_sort.py b/sorts/intro_sort.py index 20ee79c4dc7e..0ba5809fe101 100644 --- a/sorts/intro_sort.py +++ b/sorts/intro_sort.py @@ -23,7 +23,7 @@ def insertion_sort(array: list, start: int = 0, end: int = 0) -> list: >>> array = [73.568, 73.56, -45.03, 1.7, 0, 89.45] >>> insertion_sort(array, 0, len(array)) [-45.03, 0, 1.7, 73.56, 73.568, 89.45] - + """ end = end or len(array) for i in range(start, end): @@ -66,7 +66,7 @@ def heap_sort(array: list) -> list: ['b', 'b', 'd', 'e', 'e', 'f', 'g', 'i', 'm', 'p', 's', 'u', 'v', 'w', 'x', 'z'] >>> heap_sort([6.2, -45.54, 8465.20, 758.56, -457.0, 0, 1, 2.879, 1.7, 11.7]) [-457.0, -45.54, 0, 1, 1.7, 2.879, 6.2, 11.7, 758.56, 8465.2] - + """ n = len(array) From 327a53227daffc9bf95085b54ceab542de21dd36 Mon Sep 17 00:00:00 2001 From: Arya Hariharan <84255987+Arya-Hari@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:12:03 +0530 Subject: [PATCH 3/5] Update intro_sort.py --- sorts/intro_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/intro_sort.py b/sorts/intro_sort.py index 0ba5809fe101..a57084b536f0 100644 --- a/sorts/intro_sort.py +++ b/sorts/intro_sort.py @@ -62,7 +62,7 @@ def heap_sort(array: list) -> list: [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] >>> heap_sort([-2, -11, 0, 0, 0, 87, 45, -69, 78, 12, 10, 103, 89, 52]) [-69, -11, -2, 0, 0, 0, 10, 12, 45, 52, 78, 87, 89, 103] - >>> heap_sort(['b', 'd', 'e', 'f', 'g', 'p', 'x', 'z', 'b', 's', 'e' , 'u' , 'v', 'w', 'i', 'm']) + >>> heap_sort(['b', 'd', 'e', 'f', 'g', 'p', 'x', 'z', 'b', 's', 'e', 'u', 'v', 'w', 'i', 'm']) ['b', 'b', 'd', 'e', 'e', 'f', 'g', 'i', 'm', 'p', 's', 'u', 'v', 'w', 'x', 'z'] >>> heap_sort([6.2, -45.54, 8465.20, 758.56, -457.0, 0, 1, 2.879, 1.7, 11.7]) [-457.0, -45.54, 0, 1, 1.7, 2.879, 6.2, 11.7, 758.56, 8465.2] From cd16960052b09d3ca922f9a26a2239284ea78ee6 Mon Sep 17 00:00:00 2001 From: Arya Hariharan <84255987+Arya-Hari@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:19:41 +0530 Subject: [PATCH 4/5] Update intro_sort.py --- sorts/intro_sort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sorts/intro_sort.py b/sorts/intro_sort.py index a57084b536f0..1c84dd0e308a 100644 --- a/sorts/intro_sort.py +++ b/sorts/intro_sort.py @@ -62,8 +62,8 @@ def heap_sort(array: list) -> list: [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79] >>> heap_sort([-2, -11, 0, 0, 0, 87, 45, -69, 78, 12, 10, 103, 89, 52]) [-69, -11, -2, 0, 0, 0, 10, 12, 45, 52, 78, 87, 89, 103] - >>> heap_sort(['b', 'd', 'e', 'f', 'g', 'p', 'x', 'z', 'b', 's', 'e', 'u', 'v', 'w', 'i', 'm']) - ['b', 'b', 'd', 'e', 'e', 'f', 'g', 'i', 'm', 'p', 's', 'u', 'v', 'w', 'x', 'z'] + >>> heap_sort(['b', 'd', 'e', 'f', 'g', 'p', 'x', 'z', 'b', 's', 'e', 'u', 'v']) + ['b', 'b', 'd', 'e', 'e', 'f', 'g', 'p', 's', 'u', 'v', 'x', 'z'] >>> heap_sort([6.2, -45.54, 8465.20, 758.56, -457.0, 0, 1, 2.879, 1.7, 11.7]) [-457.0, -45.54, 0, 1, 1.7, 2.879, 6.2, 11.7, 758.56, 8465.2] From b05f0d552e726bce0b7dfef8cb45925a49a9118d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Oct 2023 07:52:09 +0100 Subject: [PATCH 5/5] Remove blank lines --- sorts/intro_sort.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sorts/intro_sort.py b/sorts/intro_sort.py index 1c84dd0e308a..5a5741dc8375 100644 --- a/sorts/intro_sort.py +++ b/sorts/intro_sort.py @@ -23,7 +23,6 @@ def insertion_sort(array: list, start: int = 0, end: int = 0) -> list: >>> array = [73.568, 73.56, -45.03, 1.7, 0, 89.45] >>> insertion_sort(array, 0, len(array)) [-45.03, 0, 1.7, 73.56, 73.568, 89.45] - """ end = end or len(array) for i in range(start, end): @@ -66,7 +65,6 @@ def heap_sort(array: list) -> list: ['b', 'b', 'd', 'e', 'e', 'f', 'g', 'p', 's', 'u', 'v', 'x', 'z'] >>> heap_sort([6.2, -45.54, 8465.20, 758.56, -457.0, 0, 1, 2.879, 1.7, 11.7]) [-457.0, -45.54, 0, 1, 1.7, 2.879, 6.2, 11.7, 758.56, 8465.2] - """ n = len(array)