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.
Insertion Sort - Part 2
Insertion Sort - Part 2
Sort by
recency
|
555 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can watch the explanation here : https://youtu.be/419S35Kb4Nw
My solution using Python.
Python 3
Python 3
def insertionSort1(n, arr): # Write your code here tmp=arr[n-1] i=n-1 while i>0 and arr[i-1]>tmp: arr[i]=arr[i-1] i-=1 arr[i]=tmp def printArr(arr): for i in arr: print(i,end=" ") print() def insertionSort2(n, arr): # Write your code here for i in range(2,n+1): insertionSort1(i,arr)
printArr(arr)