Computer Science, asked by yatin3256, 9 months ago

Write a python prog using insertion sort method to sort the deatils of the doctor by theri specification in decsending order

Answers

Answered by Ghostlegend
0

Answer:

Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands.

program for implementation of Insertion Sort  

 

# Function to do insertion sort  

def insertionSort(arr):  

 

   # Traverse through 1 to len(arr)  

   for i in range(1, len(arr)):  

 

       key = arr[i]  

 

       # Move elements of arr[0..i-1], that are  

       # greater than key, to one position ahead  

       # of their current position  

       j = i-1

       while j >=0 and key < arr[j] :  

               arr[j+1] = arr[j]  

               j -= 1

       arr[j+1] = key  

 

 

# Driver code to test above  

arr = [12, 11, 13, 5, 6]  

insertionSort(arr)  

print ("Sorted array is:")  

for i in range(len(arr)):  

   print ("%d" %arr[i])

pls mark as brainliest

Similar questions