File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -159,30 +159,31 @@ def insertionSort(self):
159159 descending_sort = (
160160 i > 0 and self .list [i - 1 ] < current and not self .ascending
161161 )
162- if not ascending_sort and not descending_sort :
162+ if not ( ascending_sort or descending_sort ) :
163163 break
164164 self .list [i ], self .list [i - 1 ] = self .list [i - 1 ], current
165165 i -= 1
166166 yield True
167167
168- # TODO descending functionality https://www.geeksforgeeks.org/merge-sort/
169168 def mergeSort (self , start = 0 , end = False ):
170169 if not end :
171170 end = self .bars
172171 if end - start > 1 :
173- middle = (start + end ) // 2
172+ mid = (start + end ) // 2
174173
175- yield from self .mergeSort (start , middle )
176- yield from self .mergeSort (middle , end )
177- left = self .list [start :middle ]
178- right = self .list [middle :end ]
174+ yield from self .mergeSort (start , mid )
175+ yield from self .mergeSort (mid , end )
176+ left = self .list [start :mid ]
177+ right = self .list [mid :end ]
179178
180179 a = 0
181180 b = 0
182181 c = start
183182
184183 while a < len (left ) and b < len (right ):
185- if left [a ] < right [b ]:
184+ if (left [a ] < right [b ] and self .ascending ) or (
185+ left [a ] > right [b ] and not self .ascending
186+ ):
186187 self .list [c ] = left [a ]
187188 a += 1
188189 else :
You can’t perform that action at this time.
0 commit comments