Guest User

Untitled

a guest
Nov 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. def partition(sample, start, end):
  2. # print("sample = ",sample)
  3. pivot = sample[end]
  4. index = start
  5. current = start
  6. while (current < end):
  7. if (sample[current] <= pivot):
  8. sample[index], sample[current] = sample[current], sample[index]
  9. index += 1
  10. current += 1
  11. sample[end], sample[index] = sample[index], sample[end]
  12. # print("partitioned = ",sample)
  13. return index
  14.  
  15.  
  16. def quicksort(sample, start, end):
  17. if (start < end):
  18. index = partition(sample, start, end)
  19. quicksort(sample, start, index - 1)
  20. quicksort(sample, index + 1, end)
  21.  
  22. sample = []
  23. n = int(input("enter the total no. of elements "))
  24. for i in range(n):
  25. element = int(input("enter element : "))
  26. sample.append(element)
  27.  
  28. quicksort(sample, 0, n-1)
  29. print(sample)
Add Comment
Please, Sign In to add comment