fds5
fds5
ASSIGNMENT 5
CODE:
def insertionsort(l1):
n = len(l1)
key = l1[i]
j = i-1
l1[j+1] = l1[j]
j -= 1
l1[j+1] = key
l1 = [99,23,45,56,67.5,23,45,78,67,34]
insertionsort(l1)
OUTPUT:
The array before applying insertion sort was [99, 23, 45, 56, 67.5, 23,
45, 78, 67, 34]
The array after applying insertion sort is : [23, 23, 34, 45, 45, 56, 67,
67.5, 78, 99]
CODE:
gap = n // 2
j=i
j -= gap
l1[j] = temp
gap //= 2
n = len(l1)
shellsort(l1, n)
l1.sort(reverse=True)
print(l1)
l2=[]
l2.append(l1[i])
OUTPUT:
Array before sorting: [90.3, 81.4, 30.5, 70, 53, 65, 42, 100, 90, 40]
array after applying shell sort : [30.5, 40, 42, 53, 65, 70, 81.4, 90, 90.3,
100]
[100, 90.3, 90, 81.4, 70, 65, 53, 42, 40, 30.5]
The top 5 scores are : [100, 90.3, 90, 81.4, 70]