I think you're right, this is very similar to sorting an insert .
This fragment assumes that A[0] already inserted. If n == 0 , then the check k > 0 will fail, and execution will continue to work in A[k] = key; by correctly storing the first element in the array.
This snippet also suggests that A[0:n-1] already sorted. It checks A[n] and starts scanning the array backward, moving forward in one place each element that is larger than the original A[n] .
As soon as the scan finds an element that is less than or equal to the key, it inserts it into this place.
source share