Guest User

Untitled

a guest
Nov 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def partition(lst,low,high):
  2. i = (low-1)
  3. pivot = lst[high]
  4. for j in range(low,high):
  5. if lst[j]<=pivot:
  6. i = i+1
  7. lst[i],lst[j] = lst[j],lst[i]
  8. lst[i+1],lst[high] = lst[high],lst[i+1]
  9. return (i+1)
  10.  
  11. def quicksort(lst,low,high):
  12. if low<high:
  13. pi = partition(lst,low,high)
  14. quicksort(lst,low,pi-1)
  15. quicksort(lst,pi+1,high)
  16.  
  17. a = []
  18. b = int(input("enter no of elements"))
  19. for i in range(b):
  20. c = int(input("enter no. one by one"))
  21. a.append(c)
  22. print(a)
  23. n = len(a)
  24. quicksort(a,0,n-1)
  25. print("sorted list as : ")
  26. for i in range(n):
  27. print("%d"%a[i])
Add Comment
Please, Sign In to add comment