Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit bcc9398

Browse files
Update counting_sort.py
1 parent 02c26f8 commit bcc9398

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

sorting/counting_sort.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3-
# author: bt3gl
43

54

6-
def counting_sort(list):
5+
def counting_sort(array):
76

8-
K = max(lst)
9-
counts = [0] * (K + 1)
10-
for elem in lst:
11-
counts[elem] += 1
7+
k = max(array)
8+
counts = [0] * (k + 1)
9+
10+
for e in array:
11+
counts[e] += 1
1212

1313
starting_index = 0
1414
for i, count in enumerate(counts):
1515
counts[i] = starting_index
1616
starting_index += count
1717

18-
sorted_lst = [0] * len(lst)
18+
sorted_list = [0] * len(array)
1919

20-
for elem in lst:
20+
for e in array:
2121

22-
sorted_lst[counts[elem]] = elem
23-
counts[elem] += 1
22+
sorted_list[counts[e]] = e
23+
counts[e] += 1
2424

25-
for i in range(len(lst)):
26-
lst[i] = sorted_lst[i]
25+
for i in range(len(array)):
26+
array[i] = sorted_list[i]

0 commit comments

Comments
 (0)