首页 > 其他 > 详细

Software Tesing HW1 an error in my program

时间:2017-02-26 19:36:33      阅读:231      评论:0      收藏:0      [点我收藏+]

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.

技术分享

 

Software Tesing HW1 an error in my program

原文:http://www.cnblogs.com/duanyihai/p/6445357.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!