From e64c8c9841910c7171b64259a7585167e8819ecf Mon Sep 17 00:00:00 2001 From: Anthony Hill Date: Mon, 16 Mar 2020 19:06:29 -0400 Subject: [PATCH 1/7] long night ahead --- Pipfile | 11 +++++++ Pipfile.lock | 20 +++++++++++++ src/iterative_sorting/iterative_sorting.py | 34 +++++++++++++--------- 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 Pipfile create mode 100644 Pipfile.lock diff --git a/Pipfile b/Pipfile new file mode 100644 index 00000000..b5846df1 --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] + +[requires] +python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 00000000..e42812c2 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,20 @@ +{ + "_meta": { + "hash": { + "sha256": "7f7606f08e0544d8d012ef4d097dabdd6df6843a28793eb6551245d4b2db4242" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.8" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": {} +} diff --git a/src/iterative_sorting/iterative_sorting.py b/src/iterative_sorting/iterative_sorting.py index e27496b3..348d96eb 100644 --- a/src/iterative_sorting/iterative_sorting.py +++ b/src/iterative_sorting/iterative_sorting.py @@ -1,30 +1,36 @@ -# TO-DO: Complete the selection_sort() function below -def selection_sort( arr ): +# TO-DO: Complete the selection_sort() function below +def selection_sort(arr): # loop through n-1 elements for i in range(0, len(arr) - 1): - cur_index = i - smallest_index = cur_index + cur_index = 0 + smallest_index = i + # num = 0 # TO-DO: find next smallest element - # (hint, can do in 3 loc) - - - - + # (hint, can do in 3 loc) + # print(arr[smallest_index]) + if arr[smallest_index] < arr[cur_index + 1]: + num = arr[smallest_index] + print(num) + + # if arr[i] < smallest_index: + # print(arr[i]) # TO-DO: swap + return arr +c = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7] +selection_sort(c) - return arr +# TO-DO: implement the Bubble Sort function below -# TO-DO: implement the Bubble Sort function below -def bubble_sort( arr ): +def bubble_sort(arr): return arr # STRETCH: implement the Count Sort function below -def count_sort( arr, maximum=-1 ): +def count_sort(arr, maximum=-1): - return arr \ No newline at end of file + return arr From 5e32a476eec0e479f5890c7735f886208296d170 Mon Sep 17 00:00:00 2001 From: Anthony Hill Date: Mon, 16 Mar 2020 19:59:45 -0400 Subject: [PATCH 2/7] selection sort --- src/iterative_sorting/iterative_sorting.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/iterative_sorting/iterative_sorting.py b/src/iterative_sorting/iterative_sorting.py index 348d96eb..e4e66726 100644 --- a/src/iterative_sorting/iterative_sorting.py +++ b/src/iterative_sorting/iterative_sorting.py @@ -2,26 +2,18 @@ def selection_sort(arr): # loop through n-1 elements for i in range(0, len(arr) - 1): - cur_index = 0 - smallest_index = i - # num = 0 + cur_index = i + smallest_index = cur_index # TO-DO: find next smallest element # (hint, can do in 3 loc) - # print(arr[smallest_index]) - if arr[smallest_index] < arr[cur_index + 1]: - num = arr[smallest_index] - print(num) - - # if arr[i] < smallest_index: - # print(arr[i]) + for j in range(cur_index, len(arr)): + if arr[j] < arr[smallest_index]: + smallest_index = j # TO-DO: swap - + arr[cur_index], arr[smallest_index] = arr[smallest_index], arr[cur_index] return arr -c = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7] -selection_sort(c) - # TO-DO: implement the Bubble Sort function below From ba32342c31777b85e93ef4b6598b3937c53694db Mon Sep 17 00:00:00 2001 From: Anthony Hill Date: Tue, 17 Mar 2020 09:50:58 -0400 Subject: [PATCH 3/7] MVP --- src/iterative_sorting/iterative_sorting.py | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/iterative_sorting/iterative_sorting.py b/src/iterative_sorting/iterative_sorting.py index e4e66726..47a75cae 100644 --- a/src/iterative_sorting/iterative_sorting.py +++ b/src/iterative_sorting/iterative_sorting.py @@ -17,12 +17,36 @@ def selection_sort(arr): # TO-DO: implement the Bubble Sort function below -def bubble_sort(arr): +# def bubble_sort(arr): +# swap = False +# if swap == True: +# arr[cur_index], arr[next_index] = arr[next_index], arr[cur_index] +# for i in range(0, len(arr)-1): +# cur_index = i +# next_index = cur_index +# # Create loop throughout next number to compare +# for j in range(cur_index, len(arr)): +# if arr[j] > arr[next_index]: +# next_index = j +# arr[cur_index], arr[next_index] = arr[next_index], arr[cur_index] +# # if curr index is greater than next index, swap +# # then add 1 to current index + +# # else if it's not, add 1 to current index and continue to next step +# return arr +def bubble_sort(arr): + swap = True + while swap: + swap = False + for i in range(0, len(arr) - 1): + if arr[i] > arr[i + 1]: + arr[i], arr[i + 1] = arr[i + 1], arr[i] + swap = True return arr +# STRETCH: implement the Count Sort function below -# STRETCH: implement the Count Sort function below def count_sort(arr, maximum=-1): return arr From f19d772149b0f8fa5bbcf1a18e4660af39869ee0 Mon Sep 17 00:00:00 2001 From: Anthony Hill Date: Tue, 17 Mar 2020 17:16:52 -0400 Subject: [PATCH 4/7] day 2 --- src/iterative_sorting/iterative_sorting.py | 18 ++++++++++++++++++ src/iterative_sorting/test_iterative.py | 15 +++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/iterative_sorting/iterative_sorting.py b/src/iterative_sorting/iterative_sorting.py index 47a75cae..b72a2f5f 100644 --- a/src/iterative_sorting/iterative_sorting.py +++ b/src/iterative_sorting/iterative_sorting.py @@ -46,7 +46,25 @@ def bubble_sort(arr): return arr # STRETCH: implement the Count Sort function below +# THIS DOESN'T WORK + def count_sort(arr, maximum=-1): + # count number of times each value appears + counts = [0] * (maximum + 1) + for num in arr: + counts[num] += 1 + + # overwrite coutns to hold next index an item to store where the next number goes + previous = 0 + for i, count in enumerate(counts): + counts[i] = previous + previous += count + + sorted_list = [None] * len(arr) + + for item in arr: + sorted_list[counts[item]] = item + counts[item] += 1 return arr diff --git a/src/iterative_sorting/test_iterative.py b/src/iterative_sorting/test_iterative.py index df11b648..437c41b7 100644 --- a/src/iterative_sorting/test_iterative.py +++ b/src/iterative_sorting/test_iterative.py @@ -2,6 +2,7 @@ import random from iterative_sorting import * + class IterativeSortingTest(unittest.TestCase): def test_selection_sort(self): arr1 = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7] @@ -9,9 +10,9 @@ def test_selection_sort(self): arr3 = [0, 1, 2, 3, 4, 5] arr4 = random.sample(range(200), 50) - self.assertEqual(selection_sort(arr1), [0,1,2,3,4,5,6,7,8,9]) + self.assertEqual(selection_sort(arr1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(selection_sort(arr2), []) - self.assertEqual(selection_sort(arr3), [0,1,2,3,4,5]) + self.assertEqual(selection_sort(arr3), [0, 1, 2, 3, 4, 5]) self.assertEqual(selection_sort(arr4), sorted(arr4)) def test_bubble_sort(self): @@ -20,21 +21,23 @@ def test_bubble_sort(self): arr3 = [0, 1, 2, 3, 4, 5] arr4 = random.sample(range(200), 50) - self.assertEqual(bubble_sort(arr1), [0,1,2,3,4,5,6,7,8,9]) + self.assertEqual(bubble_sort(arr1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) self.assertEqual(bubble_sort(arr2), []) - self.assertEqual(bubble_sort(arr3), [0,1,2,3,4,5]) + self.assertEqual(bubble_sort(arr3), [0, 1, 2, 3, 4, 5]) self.assertEqual(bubble_sort(arr4), sorted(arr4)) # Uncomment this test to test your count_sort implementation + # def test_counting_sort(self): # arr1 = [1, 5, 8, 4, 2, 9, 6, 0, 3, 7] # arr2 = [] # arr3 = [1, 5, -2, 4, 3] # arr4 = random.sample(range(200), 50) - # self.assertEqual(count_sort(arr1), [0,1,2,3,4,5,6,7,8,9]) + # self.assertEqual(count_sort(arr1), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) # self.assertEqual(count_sort(arr2), []) - # self.assertEqual(count_sort(arr3), "Error, negative numbers not allowed in Count Sort") + # self.assertEqual(count_sort( + # arr3), "Error, negative numbers not allowed in Count Sort") # self.assertEqual(count_sort(arr4), sorted(arr4)) From 4784a4985b87772926b01fb54dacc41267d03ae3 Mon Sep 17 00:00:00 2001 From: Anthony Hill Date: Wed, 18 Mar 2020 01:34:18 -0400 Subject: [PATCH 5/7] switched merge sort --- .vscode/settings.json | 3 + Pipfile | 2 + Pipfile.lock | 87 +++++++++++++++++++++- src/recursive_sorting/recursive_sorting.py | 61 ++++++++++++--- 4 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..ff826a63 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/Users/anthonyhill/.local/share/virtualenvs/Sorting-YYiHKuic/bin/python" +} \ No newline at end of file diff --git a/Pipfile b/Pipfile index b5846df1..1d79e13f 100644 --- a/Pipfile +++ b/Pipfile @@ -4,6 +4,8 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] +autopep8 = "*" +pylint = "*" [packages] diff --git a/Pipfile.lock b/Pipfile.lock index e42812c2..2cec7334 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7f7606f08e0544d8d012ef4d097dabdd6df6843a28793eb6551245d4b2db4242" + "sha256": "6c809087f55c30413ef2efc190ac156e327254cef0418ad3b1e3835b11e7b7a7" }, "pipfile-spec": 6, "requires": { @@ -16,5 +16,88 @@ ] }, "default": {}, - "develop": {} + "develop": { + "astroid": { + "hashes": [ + "sha256:71ea07f44df9568a75d0f354c49143a4575d90645e9fead6dfb52c26a85ed13a", + "sha256:840947ebfa8b58f318d42301cf8c0a20fd794a33b61cc4638e28e9e61ba32f42" + ], + "version": "==2.3.3" + }, + "autopep8": { + "hashes": [ + "sha256:0f592a0447acea0c2b0a9602be1e4e3d86db52badd2e3c84f0193bfd89fd3a43" + ], + "index": "pypi", + "version": "==1.5" + }, + "isort": { + "hashes": [ + "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1", + "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd" + ], + "version": "==4.3.21" + }, + "lazy-object-proxy": { + "hashes": [ + "sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d", + "sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449", + "sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08", + "sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a", + "sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50", + "sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd", + "sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239", + "sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb", + "sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea", + "sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e", + "sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156", + "sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142", + "sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442", + "sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62", + "sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db", + "sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531", + "sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383", + "sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a", + "sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357", + "sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4", + "sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0" + ], + "version": "==1.4.3" + }, + "mccabe": { + "hashes": [ + "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", + "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" + ], + "version": "==0.6.1" + }, + "pycodestyle": { + "hashes": [ + "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", + "sha256:e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa2b085bc0ca976c" + ], + "version": "==2.5.0" + }, + "pylint": { + "hashes": [ + "sha256:3db5468ad013380e987410a8d6956226963aed94ecb5f9d3a28acca6d9ac36cd", + "sha256:886e6afc935ea2590b462664b161ca9a5e40168ea99e5300935f6591ad467df4" + ], + "index": "pypi", + "version": "==2.4.4" + }, + "six": { + "hashes": [ + "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a", + "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c" + ], + "version": "==1.14.0" + }, + "wrapt": { + "hashes": [ + "sha256:565a021fd19419476b9362b05eeaa094178de64f8361e44468f9e9d7843901e1" + ], + "version": "==1.11.2" + } + } } diff --git a/src/recursive_sorting/recursive_sorting.py b/src/recursive_sorting/recursive_sorting.py index dcbf3757..3891eb5d 100644 --- a/src/recursive_sorting/recursive_sorting.py +++ b/src/recursive_sorting/recursive_sorting.py @@ -1,26 +1,67 @@ -# TO-DO: complete the helpe function below to merge 2 sorted arrays -def merge( arrA, arrB ): - elements = len( arrA ) + len( arrB ) - merged_arr = [0] * elements +# TO-DO: complete the helper function below to merge 2 sorted arrays +import math + + +def merge(arrA, arrB): + elements = len(arrA) + len(arrB) + merged_arr = [] # TO-DO - + # create pointers for each side, starting at 0. + # Left and right will only increment once an item is added to merged_arr + left = 0 + right = 0 + while left < len(arrA) and right < len(arrB): + if arrA[left] <= arrB[right]: + merged_arr.append(arrA[left]) + left += 1 + else: + merged_arr.append(arrB[right]) + right += 1 + # NEED TO MAKE SURE TO CONTINUE TO EMPTY ARRAYS + # BOTH LEFT AND RIGHT ARRAYS MUST BE EMPTIED FOR IT TO BE FULLY MERGED IN MERGED_ARR + while left < len(arrA): + merged_arr.append(arrA[left]) + left += 1 + while right < len(arrB): + merged_arr.append(arrB[right]) + right += 1 return merged_arr +a = [1, 3, 4, 5] +b = [2, 9, 7, 8] +c = [2, 9, 7, 8, 3, 5] +# print(merge(a, b)) + # TO-DO: implement the Merge Sort function below USING RECURSION -def merge_sort( arr ): - # TO-DO - return arr +# def merge_sort(arr): +# # TO-DO + +# return arr + +def merge_sort(arr): + if len(arr) < 2: + return arr + mid = len(arr) // 2 + left = arr[0:mid] + right = arr[mid:len(arr)] + return merge(merge_sort(left), merge_sort(right)) + + +print(merge_sort(c)) # STRETCH: implement an in-place merge sort algorithm + + def merge_in_place(arr, start, mid, end): # TO-DO return arr -def merge_sort_in_place(arr, l, r): + +def merge_sort_in_place(arr, l, r): # TO-DO return arr @@ -28,6 +69,6 @@ def merge_sort_in_place(arr, l, r): # STRETCH: implement the Timsort function below # hint: check out https://github.com/python/cpython/blob/master/Objects/listsort.txt -def timsort( arr ): +def timsort(arr): return arr From 74f8d026c752fa96aa9612d553beadc555b2dfc0 Mon Sep 17 00:00:00 2001 From: Anthony Hill Date: Mon, 13 Apr 2020 16:20:53 -0400 Subject: [PATCH 6/7] completed selection sort --- src/iterative_sorting/iterative_sorting.py | 55 +++------------------- 1 file changed, 7 insertions(+), 48 deletions(-) diff --git a/src/iterative_sorting/iterative_sorting.py b/src/iterative_sorting/iterative_sorting.py index b72a2f5f..0813ede5 100644 --- a/src/iterative_sorting/iterative_sorting.py +++ b/src/iterative_sorting/iterative_sorting.py @@ -6,65 +6,24 @@ def selection_sort(arr): smallest_index = cur_index # TO-DO: find next smallest element # (hint, can do in 3 loc) + + # progress through array looking for smaller number for j in range(cur_index, len(arr)): - if arr[j] < arr[smallest_index]: + if arr[cur_index] > arr[j]: smallest_index = j # TO-DO: swap - arr[cur_index], arr[smallest_index] = arr[smallest_index], arr[cur_index] + arr[cur_index] = arr[smallest_index] + return arr # TO-DO: implement the Bubble Sort function below - - -# def bubble_sort(arr): -# swap = False -# if swap == True: -# arr[cur_index], arr[next_index] = arr[next_index], arr[cur_index] -# for i in range(0, len(arr)-1): -# cur_index = i -# next_index = cur_index -# # Create loop throughout next number to compare -# for j in range(cur_index, len(arr)): -# if arr[j] > arr[next_index]: -# next_index = j -# arr[cur_index], arr[next_index] = arr[next_index], arr[cur_index] -# # if curr index is greater than next index, swap -# # then add 1 to current index - -# # else if it's not, add 1 to current index and continue to next step -# return arr - def bubble_sort(arr): - swap = True - while swap: - swap = False - for i in range(0, len(arr) - 1): - if arr[i] > arr[i + 1]: - arr[i], arr[i + 1] = arr[i + 1], arr[i] - swap = True - return arr -# STRETCH: implement the Count Sort function below -# THIS DOESN'T WORK + return arr +# STRETCH: implement the Count Sort function below def count_sort(arr, maximum=-1): - # count number of times each value appears - counts = [0] * (maximum + 1) - for num in arr: - counts[num] += 1 - - # overwrite coutns to hold next index an item to store where the next number goes - previous = 0 - for i, count in enumerate(counts): - counts[i] = previous - previous += count - - sorted_list = [None] * len(arr) - - for item in arr: - sorted_list[counts[item]] = item - counts[item] += 1 return arr From 1f6453c1e0622452686e4cb627270b6f1fbfcdde Mon Sep 17 00:00:00 2001 From: Anthony Hill Date: Mon, 13 Apr 2020 16:50:21 -0400 Subject: [PATCH 7/7] MVP --- .../iterative_sorting.cpython-37.pyc | Bin 815 -> 870 bytes src/iterative_sorting/iterative_sorting.py | 24 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/iterative_sorting/__pycache__/iterative_sorting.cpython-37.pyc b/src/iterative_sorting/__pycache__/iterative_sorting.cpython-37.pyc index 7176fe6aa9951159b6a50bac8891d62dd4090bdc..5116c5f22e35695e4e8dbf30fa8e4647e0516c47 100644 GIT binary patch delta 431 zcmXv~QA+|r5T2PkugmjFLP!aM2*L~Ez^4!&qN0b0D5N4I;c6r!v)U6V{Pq}}g-3Bi#bMO$ zH1FEI=5?zT?nSp39EJBiE&Wj`DP#3HmBTE$v`9+3yhH&VmZT%OB^kE`y3LN*>tG*- zIHYYjKOSKBKs1_YjCnA6c|hWZj3;882klE0wKl0HUDBSZGGjD^icQdzAg=DAFhv{GgCiFFlC#P}Gx1MXHEF#h8r*YCqfr>|uk4_6Jz< zLj;dr{4s+6z`L^neam|@k6D;E-{zZneBin(K=|zbT)%RFFKzxn9=gP|K_Wol90Cwb zaH=RQQ4!`G116UG;4d$3&uqg31&VtxfW^o2=4tC9jb++O<8Txu@u+nY4(~;nM#*^m zSOnOA;WezHg$+yU6cLhW7{m(kkeEJ@Oz$#UpP_;o&e##$^m6JIdXO`PIiI!_7i?h2 zbH#K5fpyR+$p1UtbxOAfIe*%|1Z9?=JHU$l~FoNZ8g!T_>oL0M;m| sf$J35p(pL)on19|^_=NBlP+n`N9j=Yd3lkvsh4ii=1of arr[j]: + if arr[smallest_index] > arr[j]: smallest_index = j # TO-DO: swap - arr[cur_index] = arr[smallest_index] + arr[cur_index], arr[smallest_index] = arr[smallest_index], arr[cur_index] return arr # TO-DO: implement the Bubble Sort function below -def bubble_sort(arr): +# UNDERSTAND + # Compare consecutive items + # The highest number will bubble all the way to the right with each iteration + + +def bubble_sort(arr): + # PLAN + # create first iteration that takes in the first index + for i in range(1, len(arr)): + # make another iteration that is always at the prev number + for j in range(0, len(arr) - 1): + # if 2nd number is greater than the first, swap + if arr[j] > arr[j + 1]: + arr[j], arr[j + 1] = arr[j + 1], arr[j] + # i += 1 return arr +a = [8, 2, 5, 1] +bubble_sort(a) + + # STRETCH: implement the Count Sort function below def count_sort(arr, maximum=-1):