We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import math
import os
import random
import re
import sys
#
Complete the 'insertionSort1' function below.
#
The function accepts following parameters:
1. INTEGER n
2. INTEGER_ARRAY arr
#
def insertionSort1(n, arr):
# Write your code here
for i in range(n):
j = i
curr = arr[i]
if curr < arr[j-1]:
while j > 0 and curr < arr[j-1]:
arr[j]= arr[j-1]
j-=1
print(*arr)
Insertion Sort - Part 1
You are viewing a single comment's thread. Return to all comments →
!/bin/python3
import math import os import random import re import sys
#
Complete the 'insertionSort1' function below.
#
The function accepts following parameters:
1. INTEGER n
2. INTEGER_ARRAY arr
#
def insertionSort1(n, arr): # Write your code here for i in range(n): j = i curr = arr[i] if curr < arr[j-1]: while j > 0 and curr < arr[j-1]: arr[j]= arr[j-1] j-=1 print(*arr)
if name == 'main': n = int(input().strip())