0% found this document useful (0 votes)
4 views1 page

Quick Sort Algorithm in Python

The document contains a Python implementation of the Quick Sort algorithm, which includes a partition function and a recursive quick_sort function. It prompts the user to input the size of a list and the elements to be sorted. Finally, it sorts the list using Quick Sort and prints the sorted result.

Uploaded by

sanjanajaanu580
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Quick Sort Algorithm in Python

The document contains a Python implementation of the Quick Sort algorithm, which includes a partition function and a recursive quick_sort function. It prompts the user to input the size of a list and the elements to be sorted. Finally, it sorts the list using Quick Sort and prints the sorted result.

Uploaded by

sanjanajaanu580
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#Quick Sort

a=[]
def partition(low,high):
key=a[low]
i=low+1
j=high
while(True):
while(a[i]<=key and i<high):
i=i+1
while(a[j]>key):
j=j-1
if(i<j):
temp=a[i]
a[i]=a[j]
a[j]=temp
else:
a[low]=a[j]
a[j]=key
return j

def quick_sort(low,high):
if(low<high):
j=partition(low,high)
quick_sort(low,j-1)
quick_sort(j+1,high)

n=int(input("Enter the size of List"))


i=0
while(i<n):
ele=int(input("Enter number"))
[Link](ele)
i=i+1

quick_sort(0,n-1)
print(a)

You might also like