Last week, I wanted to review sorting algorithm. So I wrote a simple program about straight insertion sort.
But when I run this program, I found that the index of the array might become -1. then there would be an out of bounds error.
So I changed the conditional statement. I modified while ( temp < a[j]) into while (j >=0 && temp < a[j])。
How did I find it?
It was an accident. I tested my program by an array of {2, -5,3,1,4,7,2,9}. Then the result was very strange. the output was not my array! it has an element of 2752460.