public static void insertSort(int [] A) {
int i,j, temp;
j = 1;
//invariant:
A[0..j-1] is sorted
while (j < A.length) {
i = j - 1;
temp = A[j];
//invariant:
for all k: i < k < j :
A[k] > temp
while ((i >= 0) && (A[i] > temp)) {
cmprs++; count+=2;
swaps++;
A[i+1] = A[i];
i--;
}
A[i+1] = temp;
cmprs++;
count++;
j++;
}
count++;
} // end insertSort