大家有没有遇到过这种情况:一个Java程序运行时会卡住,而且没有提示什么错误,但是如果用debug的模式运行就什么问题也没有!...。以前遇到过,今天闲来写了个折半插入排序,也遇到了,还是不得要领。import java.util.Random;public class BInsertSort { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
BInsertSort s = new BInsertSort();
Random ran = new Random();
int[] source = new int[7];
for (int i = 0; i < 7; i++) {
source[i] = ran.nextInt(100); }
Util.printSeq(source);
s.sort(source);
Util.printSeq(source);
} public void sort(int[] seq) {
int temp = 0;
int low = 0, high = 0;
int half = 0;
for (int i = 1; i < seq.length; i++) {
if (seq[i] < seq[i - 1]) {
temp = seq[i];
low = 0;
high = i - 1;
while (low <= high) {
half = low + high / 2;
if (seq[half] < temp)
low = half + 1;
else
high = half - 1;
}
int j = i - 1;
for (; j >= high + 1; j--)
seq[j + 1] = seq[j];
seq[j + 1] = temp; }
Util.printSeq(seq);
}
}
}

解决方案 »

  1.   

    Util.   ??这个有点问题吧 !!
      

  2.   

    那个只是打印序列而已,问题是在排序的时候卡住的,即:public void sort(int[] seq)这个地方,也没有陷入死循环,不知道怎么回事
      

  3.   

    那个只是打印序列而已,问题是在排序的时候卡住的,即:public void sort(int[] seq)这个地方,也没有陷入死循环,不知道怎么回事
      

  4.   

    half = low + high / 2; 
    --->
    half = (low + high) / 2;