Skip to content

Commit ef8803f

Browse files
authored
Updated in pep8
1 parent a8e6147 commit ef8803f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements and the number of possible key values are approximately the same.
2-
It requires O(n + Range) time where n is number of elements in input array and ‘Range’ is number of possible values in array.
1+
#Pigeonhole sorting is a sorting algorithm that is suitable for sorting lists of elements where the number of elements and the number of possible key values are approximately the same.
2+
#It requires O(n + Range) time where n is number of elements in input array and ‘Range’ is number of possible values in array.
33

44
def pigeonhole_sort(a):
5-
# size of range of values in the list
6-
# (ie, number of pigeonholes we need)
75
my_min = min(a)
86
my_max = max(a)
97
size = my_max - my_min + 1
108

119
# our list of pigeonholes
10+
11+
1212
holes = [0] * size
1313

1414
# Populate the pigeonholes.
15+
16+
1517
for x in a:
1618
assert type(x) is int, "integers only please"
1719
holes[x - my_min] += 1
1820

1921
# Put the elements back into the array in order.
22+
23+
2024
i = 0
2125
for count in range(size):
2226
while holes[count] > 0:
@@ -27,8 +31,6 @@ def pigeonhole_sort(a):
2731

2832
a = [8, 3, 2, 7, 4, 6, 8]
2933
print("Sorted order is : ", end = ' ')
30-
3134
pigeonhole_sort(a)
32-
3335
for i in range(0, len(a)):
3436
print(a[i], end = ' ')

0 commit comments

Comments
 (0)