Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def partition(lst,low,high):
- i = (low-1)
- pivot = lst[high]
- for j in range(low,high):
- if lst[j]<=pivot:
- i = i+1
- lst[i],lst[j] = lst[j],lst[i]
- lst[i+1],lst[high] = lst[high],lst[i+1]
- return (i+1)
- def quicksort(lst,low,high):
- if low<high:
- pi = partition(lst,low,high)
- quicksort(lst,low,pi-1)
- quicksort(lst,pi+1,high)
- a = []
- b = int(input("enter no of elements"))
- for i in range(b):
- c = int(input("enter no. one by one"))
- a.append(c)
- print(a)
- n = len(a)
- quicksort(a,0,n-1)
- print("sorted list as : ")
- for i in range(n):
- print("%d"%a[i])
Add Comment
Please, Sign In to add comment