Write a python function to do insertion sort


Topic: Write a python function to do insertion sort

Solution

def insertionSort(arr): 
    for i in range(1, len(arr)): 
  
        key = arr[i] 
        j = i-1
        while j >=0 and key < arr[j] : 
                arr[j+1] = arr[j] 
                j -= 1
        arr[j+1] = key 
 
 # write a python program to print prime numbers within a range
 
 lower = 5
 upper = 20
 print("Prime numbers between", lower, "and", upper, "are:")
 for num in range(lower, upper + 1):
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)
 



List all Python Programs