6. shell insertion sort
6. shell insertion sort
#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)
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 !!")