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):
3535 >>> quick_sort([-2, -5, -45])
3636 [-45, -5, -2]
3737 """
38- if len (collection ) <= 1 :
38+ total_elements = len (collection )
39+
40+ if total_elements <= 1 :
3941 return collection
4042 less = []
4143 equal = []
4244 greater = []
4345 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 )
4956 else :
50- greater .append (x )
57+ greater .append (element )
5158 return quick_sort (less ) + equal + quick_sort (greater )
5259
5360
You can’t perform that action at this time.
0 commit comments