File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -35,19 +35,26 @@ def quick_sort(collection):
35
35
>>> quick_sort([-2, -5, -45])
36
36
[-45, -5, -2]
37
37
"""
38
- if len (collection ) <= 1 :
38
+ total_elements = len (collection )
39
+
40
+ if total_elements <= 1 :
39
41
return collection
40
42
less = []
41
43
equal = []
42
44
greater = []
43
45
pivot = collection [0 ]
44
- for x in collection :
45
- if x < pivot :
46
- less .append (x )
47
- elif x == pivot :
48
- equal .append (x )
46
+
47
+ equal .append (pivot )
48
+
49
+ for i in range (1 , total_elements ):
50
+ element = collection [i ]
51
+
52
+ if element < pivot :
53
+ less .append (element )
54
+ elif element == pivot :
55
+ equal .append (element )
49
56
else :
50
- greater .append (x )
57
+ greater .append (element )
51
58
return quick_sort (less ) + equal + quick_sort (greater )
52
59
53
60
You can’t perform that action at this time.
0 commit comments