SHARE
TWEET

Untitled

a guest Jan 24th, 2020 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. input = [[1,2],[2,3],[4,1],[4,1],[2,1],[4,6],[2,1],[1,2]]
  2. def partition(arr,low,high):
  3.     i = ( low-1 )         # index of smaller element
  4.     pivot = val(arr[high])     # pivot
  5.     for j in range(low , high):
  6.         # If current element is smaller than or
  7.         # equal to pivot
  8.         if   val(arr[j]) <= pivot:
  9.             # increment index of smaller element
  10.             i = i+1
  11.             arr[i],arr[j] = arr[j],arr[i]
  12.     arr[i+1],arr[high] = arr[high],arr[i+1]
  13.     return ( i+1 )
  14. def val(inslist):
  15.     return (inslist[0]*10+inslist[1])
  16. def quickSort(arr,low,high):
  17.     if low < high:
  18.         pi = partition(arr,low,high)
  19.         quickSort(arr, low, pi-1)
  20.         quickSort(arr, pi+1, high)
  21. arr = input
  22. n = len(arr)
  23. quickSort(arr,0,n-1)
  24. print ("Sorted array is:")
  25. print(arr)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top