Insertion sort Pseudo code vs implementation?
The following two points might clear your confusion.

The pseudocode in the book is following $1$ based indexing. Your code is following $0$ based indexing.

Your code is technically doing nothing in the first iteration of the while loop. In the first iteration $i = 0$, therefore $j = -1$. Since $j&lt;0$, the inside while loop is not executed. And it keeps $A[0] = key$ to its original value. Effectively, your code starts executing from $i = 1$, which is equivalent to $j = 2$ in CLRS implementation.