Skip to content

Commit 36b35a4

Browse files
authored
Merge pull request #1 from hustcc/master
merge
2 parents fd6155a + 75a861b commit 36b35a4

File tree

7 files changed

+87
-10
lines changed

7 files changed

+87
-10
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['https://paypal.me/hustcc', 'https://atool.vip']

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ language: node_js
22
node_js:
33
- "10"
44
before_install:
5-
- npm i -g lint-md
5+
- npm i -g lint-md-cli
66
script: lint-md ./

10.radixSort.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
基数排序有两种方法:
99

10-
这三种排序算法都利用了桶的概念,但对桶的使用方法上有明显差异
10+
这三种排序算法都利用了桶的概念,但对桶的使用方法上有明显差异案例看大家发的
1111

1212
- 基数排序:根据键值的每位数字来分配桶;
1313
- 计数排序:每个桶只存储单一键值;
@@ -49,7 +49,39 @@ function radixSort(arr, maxDigit) {
4949
}
5050
```
5151

52-
## 4. Java 代码实现
52+
53+
## 4. python 代码实现
54+
55+
```python
56+
def radix(arr):
57+
58+
digit = 0
59+
max_digit = 1
60+
max_value = max(arr)
61+
#找出列表中最大的位数
62+
while 10**max_digit < max_value:
63+
max_digit = max_digit + 1
64+
65+
while digit < max_digit:
66+
temp = [[] for i in range(10)]
67+
for i in arr:
68+
#求出每一个元素的个、十、百位的值
69+
t = int((i/10**digit)%10)
70+
temp[t].append(i)
71+
72+
coll = []
73+
for bucket in temp:
74+
for i in bucket:
75+
coll.append(i)
76+
77+
arr = coll
78+
digit = digit + 1
79+
80+
return arr
81+
```
82+
83+
84+
## 5. Java 代码实现
5385

5486
```java
5587
/**
@@ -134,7 +166,7 @@ public class RadixSort implements IArraySort {
134166
}
135167
```
136168

137-
## 5. PHP 代码实现
169+
## 6. PHP 代码实现
138170

139171
```php
140172
function radixSort($arr, $maxDigit = null)
@@ -169,4 +201,4 @@ function radixSort($arr, $maxDigit = null)
169201

170202
return $arr;
171203
}
172-
```
204+
```

4.shellSort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class ShellSort implements IArraySort {
9999
int[] arr = Arrays.copyOf(sourceArray, sourceArray.length);
100100

101101
int gap = 1;
102-
while (gap < arr.length) {
102+
while (gap < arr.length/3) {
103103
gap = gap * 3 + 1;
104104
}
105105

7.heapSort.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
## 1. 算法步骤
1212

13-
1. 创建一个堆 H[0……n-1]
13+
1. 将待排序序列构建成一个堆 H[0……n-1],根据(升序降序需求)选择大顶堆或小顶堆
1414

1515
2. 把堆首(最大值)和堆尾互换;
1616

@@ -254,4 +254,4 @@ function heapSort($arr) {
254254
}
255255
return $arr;
256256
}
257-
```
257+
```

8.countingSort.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ function countingSort($arr, $maxValue = null)
149149

150150
$sortedIndex = 0;
151151
foreach ($bucket as $key => $len) {
152-
if ($len !== null) $arr[$sortedIndex++] = $key;
152+
if($len !== null){
153+
for($j = 0; $j < $len; $j++){
154+
$arr[$sortedIndex++] = $key;
155+
}
156+
}
153157
}
154158

155159
return $arr;

src/pythonSortTest.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'''
1+
'''
22
# Create by LokiSharp(loki.sharp#gmail) at 2017-1-22
33
'''
44

@@ -176,6 +176,34 @@ def countingSort(arr, maxValue=None):
176176
bucket[j] -= 1
177177
return arr
178178

179+
def radix_count(exp1):
180+
global list
181+
n = len(list)
182+
output = [0] * (n)
183+
count = [0] * (10)
184+
for i in range(0, n):
185+
index = (list[i] / exp1)
186+
count[(index) % 10] += 1
187+
for i in range(1,10):
188+
count[i] += count[i - 1]
189+
i = n - 1
190+
while i >= 0:
191+
index = (list[i]/exp1)
192+
output[count[(index) % 10] - 1] = list[i]
193+
count[(index) % 10] -= 1
194+
i -= 1
195+
i = 0
196+
for i in range(0,len(list)):
197+
list[i] = output[i]
198+
199+
def radixSort():
200+
global list
201+
max1 = max(list)
202+
exp = 1
203+
while max1 / exp > 0:
204+
radix_count(exp)
205+
exp *= 10
206+
179207

180208
if __name__ == '__main__':
181209
sortTest(bubbleSort, TOTAL)
@@ -185,3 +213,4 @@ def countingSort(arr, maxValue=None):
185213
sortTest(mergeSort, TOTAL)
186214
sortTest(quickSort, TOTAL)
187215
sortTest(heapSort, TOTAL)
216+
sortTest(radixSort, TOTAL)

0 commit comments

Comments
 (0)