0% found this document useful (0 votes)
8 views3 pages

Ds 6

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)
8 views3 pages

Ds 6

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
You are on page 1/ 3

Name :

Nisha Kadam
Department : Computer
Engineering
Class : SE C
Roll No. : 75
Subject : Fundamentals of Data
Structure
---------------------------------------------------------------------------------------------------------------

Assignment –6
PROBLEM STATEMENT:-

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..
------------------------------------------------------------------------------

PROGRAM:-
def accept_array(A):
n = int(input("Enter the total no. of student : "))
for i in range(n):
x = float(input("Enter the first year percentage of student %d : "%(i+1)))
A.append(x)
print("Array accepted successfully\n\n");
def display_array(A):
n = len(A)
if(n == 0) :
print("\nNo records in the database")
else :
print("Array of FE Marks : ",end=' ')
for i in range(n) :
print("%.2f "%A[i],end=' ')
print("\n");
def partition(A,s,l) :
b=s+1
e=l
while(e>=b) :
while(b<=l and A[s] >= A[b]) :
b=b+1
while(A[s] <A[e]) :
e=e-1
if(e>b) :
temp = A[e]
A[e] = A[b]
A[b] = temp
temp = A[s]
A[s] = A[e]
A[e] = temp
return e
def Quicksort(A,s,l) :
if(s<l) :
mid = partition(A,s,l)
Quicksort(A,s,mid-1)
Quicksort(A,mid+1,l)
def Main() :
A = []
while True :
print ("\t1 : Accept & Display the FE Marks")
print ("\t2 : Quick sort ascending order and display top five scores")
print ("\t3 : Exit")
ch = int(input("Enter your choice : "))
if (ch == 3):
print ("End of Program")
quit()
elif (ch==1):
A = []
accept_array(A)
display_array(A)
elif (ch==2):
print("Marks before sorting")
display_array(A)
n =len(A)
Quicksort(A,0,n-1)
print("Marks after sorting")
display_array(A)
if(n >= 5) :
print("Top Five Scores : ")
for i in range(n-1,n-6,-1) :
print("\t%.2f"%A[i])
else :
print("Top Scorers : ")
for i in range(n-1,-1,-1) :
print("\t%.2f"%A[i])
else :
print ("Wrong choice entered !! Try again")
Main()

OUTPUT :-
(base) tpo@tpo-Vostro-3902:~$ cdSECOC75
(base) tpo@tpo-Vostro3902:~/SECOC75$
g++ i.cpp
(base) tpo@tpo-Vostro-3902:~/SECOC75$ ./a.out

1 : Accept & Display the FE Marks


2 : Quick sort ascending order and display top five scores
3 : Exit
Enter your choice : 1
Enter the total no. of student : 2
Enter the first year percentage of student 1 : 40
Enter the first year percentage of student 2 : 50
Array accepted successfully

Array of FE Marks : 40.00 50.00

1 : Accept & Display the FE Marks


2 : Quick sort ascending order and display top five scores
3 : Exit
Enter your choice : 2
Marks before sorting
Array of FE Marks : 40.00 50.00

Marks after sorting


Array of FE Marks : 40.00 50.00

Top Scorers :
50.00
40.00
1 : Accept & Display the FE Marks
2 : Quick sort ascending order and display top five scores
3 : Exit
Enter your choice :3

You might also like