Skip to content

Commit 9aa70c8

Browse files
author
Brett
committed
## 0.1.4 - sorter
- Merged [garroadran](https://github.com/garroadran) additions and changes. Changed sorts to sort a cloned list rather then in place. - README.md updated to reflect [garroadran](https://github.com/garroadran) changes. - UnitTests updated and working correctly. - setup.py updated now at version 0.1.4.
1 parent 52cf063 commit 9aa70c8

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Sort Integers using different sorting algorithms!
1515
5. [Quick](https://en.wikipedia.org/wiki/Quicksort)
1616
6. [Radix](https://en.wikipedia.org/wiki/Radix_sort)
1717
7. [Insertion](https://en.wikipedia.org/wiki/Insertion_sort)
18-
8. [Heap](https://en.wikipedia.org/wiki/Heapsort)
18+
8. [Recursive Insertion](https://en.wikipedia.org/wiki/Insertion_sort)
19+
9. [Heap](https://en.wikipedia.org/wiki/Heapsort)
1920

2021
#### Arguments
2122

@@ -75,7 +76,8 @@ an array and checks it sorted iteratively, larger data sets will take a long tim
7576

7677
## Authors
7778

78-
* **Brett Currie** - [becurrie](https://github.com/becurrie)
79+
* [**becurrie**](https://github.com/becurrie)
80+
* [**garroadran**](https://github.com/garroadran) - Heap, Insertion, Recursive Insertion algorithms.
7981

8082
See also the list of [contributors](https://github.com/becurrie/py-custom-sorters/contributors) who participated in this project.
8183

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name='sorter',
55
author_email='brettecurrie@gmail.com',
66
author='becurrie',
7-
version='0.1.3',
7+
version='0.1.4',
88
description='sort integers with different sorting algorithms.',
99
packages=find_packages(),
1010
py_modules=['sorter.sorter'],

sorter/sorts.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def quick_sort_partition(integers, first, last):
148148
return right
149149

150150

151-
def counting_sort(integers, exp):
151+
def counting_sort(integers, exp):
152152
"""Counting sort helper method used with the radix_sort()"""
153153
n = len(integers)
154154

@@ -204,11 +204,13 @@ def insertion_sort(integers):
204204
integers_clone[j], integers_clone[j-1] = integers_clone[j-1], integers_clone[j]
205205
j -= 1
206206

207-
return integers_clone
207+
return integers_clone
208+
208209

209210
def insertion_sort_recur(integers):
210211
"""Performs insertion sort recursively."""
211212
integers_clone = list(integers)
213+
212214
def helper(arr, n):
213215
if n > 0:
214216
helper(arr, n-1)
@@ -219,6 +221,7 @@ def helper(arr, n):
219221
helper(integers_clone, len(integers_clone) - 1)
220222
return integers_clone
221223

224+
222225
def heap_sort(integers):
223226
"""Sorts elements by first building an array that fulfills the
224227
maxheap property. Once the original array has been modified
@@ -232,7 +235,7 @@ def heap_sort(integers):
232235
# Reorganize the array so that it has the maxheap property
233236
n = len(integers_clone)
234237
for i in range(n, -1, -1):
235-
max_heapify(intgers_clone, i, n)
238+
max_heapify(integers_clone, i, n)
236239

237240
# Swap the biggest element with the last element in the array
238241
# Then fix the maxheap property on everything except the
@@ -245,6 +248,7 @@ def heap_sort(integers):
245248

246249
return integers_clone
247250

251+
248252
def max_heapify(arr, i, n):
249253
"""Corrects a violation of the maxheap property, provided the
250254
subtrees on the left and right of arr[i] are max heaps.

test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ def test_insertion_recur(self):
8585

8686
def test_heap_sort(self):
8787
"""Test the heap sort function."""
88-
integers = heap_sort(clone)
88+
integers = heap_sort(self.actual)
8989
self.assertEqual(self.expected, integers)

0 commit comments

Comments
 (0)