JAVA快速排序算法,程序运行,显示错误栈溢出,请大神帮我看看为什么;

import java.util.Scanner;
public class Quicksort {
public static int tempnum;
static
{
tempnum=0;
}
public static int exchange;
static
{
exchange=0;
}
public static void main(String args[])//主函数;
{
Scanner num=new Scanner(System.in);
int [] array1 =new int[8];
for(int cycle=0;cycle<8;cycle++)
{
array1[cycle]=num.nextInt();
}
scan1(array1);
for(;tempnum<array1.length;tempnum++)
{
System.out.print(array1[tempnum]);
System.out.print(" ");
}
}
public static void quicksort(int []q,int low,int high)//循环递归;
{
if(low<high)
{
int middle1=quicksortr(low,q,high);
quicksort(q,low,middle1-1);
quicksort(q,middle1+1,high);
}
}
public static int quicksortr(int low,int []array,int high)//此方法用来做数组排序分割;
{
int qi1=array[low];//数组第一个元素作为中间值;
while(low<high)
{
while(array[high]>=qi1)
{
high--;
}
exchange=array[low];
array[low]=array[high];
array[high]=exchange;
while(array[low]<=qi1)
{
low++;
}
exchange=array[high];
array[high]=array[low];
array[low]=exchange;
}
//qi1=array[low];
return low;
}
public static void scan1(int q[])
{
if(q.length>0)
{
quicksort(q,0,q.length-1);
}
else
{
System.out.println("数组为空");
}
}
}

我运行的结果不是“栈溢出”,而是数组下标越界。
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
...
用的测试数据是:
int[] array1 = {2, 1, 3, 7, 6, 4, 5, 0};

请题主再检查一下错误信息?最好原样完整地贴出来,追问

确实,是下标越界,这个是为什么呢?我查不到,能帮我看下吗?我加了50分

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网