Data Structure Lab :
Practical B16 :
Write a Python program to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using quick sort and display top five scores.
The Code for above problem is as follows :
# sppucseguru
arr=[]
n=int(input("Enter Total no. of Students "))
for i in range(n):
ele=float(input("Enter Percentage "))
arr.append(ele)
print("Before Sorting : ",arr)
def Partition(arr,low,high):
pivot=arr[high]
pindex=low
for i in range(low,high):
if arr[i]<pivot:
arr[i],arr[pindex]=arr[pindex],arr[i]
pindex+=1
arr[pindex],arr[high]=arr[high],arr[pindex]
return pindex
def QSort(arr,low,high):
if low<high:
pindexNew=Partition(arr, low, high)
QSort(arr,low,pindexNew-1)
QSort(arr,pindexNew+1,high)
QSort(arr,0,n-1)
print("After Sorting : ",arr)
Comments
Post a Comment