0% found this document useful (0 votes)
3 views

6. shell insertion sort

Uploaded by

ppawar612006
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

6. shell insertion sort

Uploaded by

ppawar612006
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

from math import floor

#Input of Marks
marks=[]
n=int(input("Enter the no. of students :"))
for i in range(0,n):
ele=float(input("Enter the Second Year Percentage :"))
marks.append(ele)

print("Second-Year Percentage List Before Sorting")


print(marks)

def InsertionSort(marks,n):
#Insertion Sort
for i in range(0,n):
index = marks[i]
j = i-1
while j>=0 and index<marks[j]:
marks[j+1]=marks[j]
j-=1
marks[j+1]=index

def ShellSort(marks,n):
#Shell Sort
gap=floor(n/2)
while gap>0:
for i in range(0,n):
temp=marks[i]
j = i
while j >= gap and marks[j-gap] >temp:
marks[j] = marks[j-gap]
j -= gap
marks[j] = temp
gap = floor(gap/2)

#Sorting Algorithms
print("\n\t * * * MENU * * *")
print("1. Insertion Sort\n2. Shell Sort")
ch=int(input("Enter your choice :"))
if(ch==1):
print("Second-Year Percentage List After Sorting :")
InsertionSort(marks, n)
print(marks)
elif(ch==2):
print("Second-Year Percentage List After Sorting :")
ShellSort(marks,n)
print(marks)
else:
print("Wrong Input !!")

You might also like