You are on page 1of 1

Bingo Sort

def bingosort(self,lst): m=len(lst)-1 nextValue=lst[m] for i in range(m,-1,-1): if lst[i]>nextValue: nextValue=lst[i] while m>0 and lst[m]==nextValue: m=m-1 while m>0: value=nextValue nextValue=lst[m] for i in range(m,-1,-1): if lst[i]==value: a=lst[i] lst[i]=lst[m] lst[m]=a m=m-1 else: if lst[i]>nextValue: nextValue=lst[i] while m>0 and lst[m]==nextValue: m=m-1 return lst

Merge Sort
def mergesort(self,lst): if len(lst) <= 1: return lst middle = int( len(lst) / 2 ) left = self.mergesort(lst[:middle]) right = self.mergesort(lst[middle:]) return self.merge(left, right) def merge(self,left, right): result = [] i ,j = 0, 0 while i < len(left) and j < len(right): if left[i] <= right[j]: result.append(left[i]) i += 1 else: result.append(right[j]) j += 1 result += left[i:] result += right[j:] return result

You might also like