def quickSort(data_list):  
   quickSortHlp(data_list,0,len(data_list)-1)  
  
def quickSortHlp(data_list,first,last):  
   if first < last:  
  
       splitpoint = partition(data_list,first,last)  
  
       quickSortHlp(data_list,first,splitpoint-1)  
       quickSortHlp(data_list,splitpoint+1,last)  
  
  
def partition(data_list,first,last):  
   pivotvalue = data_list[first]  
  
   left = first+1  
   right = last  
  
   done = False  
   while not done:  
  
       while left <= right and data_list[left] <= pivotvalue:  
           left = left + 1  
  
       while data_list[right] >= pivotvalue and right >= left:  
           right = right -1  
  
       if right < left:  
           done = True  
       else:  
           temp = data_list[left]  
           data_list[left] = data_list[right]  
           data_list[right] = temp  
  
   temp = data_list[first]  
   data_list[first] = data_list[right]  
   data_list[right] = temp  
  
  
   return right  
  
data_list = [88,75,12,98,2,47,22,39,41,7,89,71,99]
quickSort(data_list)  
print(data_list)

Output :

[2, 7, 12, 22, 39, 41, 47, 71, 75, 88, 89, 98, 99]

Add a Comment

Add a Comment