Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def partition(sample, start, end):
- # print("sample = ",sample)
- pivot = sample[end]
- index = start
- current = start
- while (current < end):
- if (sample[current] <= pivot):
- sample[index], sample[current] = sample[current], sample[index]
- index += 1
- current += 1
- sample[end], sample[index] = sample[index], sample[end]
- # print("partitioned = ",sample)
- return index
- def quicksort(sample, start, end):
- if (start < end):
- index = partition(sample, start, end)
- quicksort(sample, start, index - 1)
- quicksort(sample, index + 1, end)
- sample = []
- n = int(input("enter the total no. of elements "))
- for i in range(n):
- element = int(input("enter element : "))
- sample.append(element)
- quicksort(sample, 0, n-1)
- print(sample)
Add Comment
Please, Sign In to add comment