human
Give me a code to recursive Insertion Sort and the other steps required given the following:
Recursive Insertion Sort | Recursive function to sort an array using insertion sort.
base case.
Sort first n - 1 elements.
Insert last element at its correct position in sorted array ..
Move elements of arr [ 0. . i - 1 ] , that are greater than key , to one position ahead of their current position.
A utility function to print an array of size n.
Driver program to test insertion sort"
How can the above be solved in Python?
assistant
#Here is code to recursive Insertion Sort and the other steps required.
 def insertionSortRecursive ( arr , n ) :
	if n <= 1 :
		return
	insertionSortRecursive ( arr , n - 1 )
	last = arr [ n - 1 ]
	j = n - 2
	while ( j >= 0 and arr [ j ] > last ) :
		arr [ j + 1 ] = arr [ j ]
		j = j - 1
	arr [ j + 1 ] = last
def printArray ( arr , n ) :
	for i in range ( n ) :
		print arr [ i ] ,
arr = [ 12 , 11 , 13 , 5 , 6 ]
n = len ( arr )
insertionSortRecursive ( arr , n )
printArray ( arr , n )