1 #!/usr/bin/env python2 2 # -*- coding: utf-8 -*- 3 """ 4 Created on Tue Nov 21 22:28:09 2017 5 6 @author: livermorium116 7 """ 8 9 10 11 12 import random13 14 class MergeSortedByCur():15 def __init__(self, data):16 self.data = data17 #print("ORIGIN DATA:", self.data)18 self.CountCur=019 self.Results=self.MergeSort(self.data)20 def MergeSort(self,data):21 22 if len(data) <= 1:23 return data24 num = int(len(data)/2)25 Left = self.MergeSort(data[:num])26 Right = self.MergeSort(data[num:])27 #print("LEFT:",Left,"RIGHT:",Right)28 self.CountCur += 129 #print ("%d Cursions:"%(self.CountCur))30 return self.Merge(Left, Right)31 32 33 def Merge(self,left, right):34 R, L = 0, 035 result = []36 while L < len(left ) and R < len(right ):37 if left[L] < right[R]:38 result.append(left[L])39 L += 140 else:41 result.append(right[R])42 R += 143 result.extend(left[L:])44 result.extend(right[R:])45 #print("MergeSorted DATA:",result)46 return result47 48 49 50 51 52 53 54 55 if __name__ == "__main__":56 data = [random.randint(1,100) for i in range(13)]57 print(data)58 print MergeSortedByCur(data).Results59