File tree 1 file changed +8
-8
lines changed
1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 12
12
from __future__ import print_function
13
13
14
14
15
- def quick_sort (ARRAY ):
15
+ def quick_sort (collection ):
16
16
"""Pure implementation of quick sort algorithm in Python
17
17
18
18
:param collection: some mutable ordered collection with heterogeneous
@@ -29,14 +29,14 @@ def quick_sort(ARRAY):
29
29
>>> quick_sort([-2, -5, -45])
30
30
[-45, -5, -2]
31
31
"""
32
- ARRAY_LENGTH = len (ARRAY )
33
- if ( ARRAY_LENGTH <= 1 ) :
34
- return ARRAY
32
+ length = len (collection )
33
+ if length <= 1 :
34
+ return collection
35
35
else :
36
- PIVOT = ARRAY [0 ]
37
- GREATER = [ element for element in ARRAY [1 :] if element > PIVOT ]
38
- LESSER = [ element for element in ARRAY [1 :] if element <= PIVOT ]
39
- return quick_sort (LESSER ) + [PIVOT ] + quick_sort (GREATER )
36
+ pivot = collection [0 ]
37
+ greater = [element for element in collection [1 :] if element > pivot ]
38
+ lesser = [element for element in collection [1 :] if element <= pivot ]
39
+ return quick_sort (lesser ) + [pivot ] + quick_sort (greater )
40
40
41
41
42
42
if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments