A = [n, ...,k]                          # inital unsorted array

function insertion_sort(A):             # insertion sort function
	i = 1  
	while i < A.length                  # run main loop from 1 to length of array
		key = A[i]                      # define the current key as the variable at index i
		j = i - 1                       # define index of the adjacent variable as i - 1
		while j >= 0 and A[j] < key:    # while the variable at the adjacent index is less than the key  
			A[j + 1] = A[j]             # swap the two variables
			j = j - 1                   # decrement position of variables being compared to make sure untill we reach j = 0 
		
		A[j + 1] = key                  # update the array
		i = i + 1                       # update the index

	return A                            # return the sorted array

sorted_array = insertion_sort(A)