最近接触了个OAF的项目,开始学Java,在测试堆排序时出现个问题,就是:在Java中使用堆排序,当整数数目超过10000个时会报堆栈溢出错误,在我的机器上(>8970)就会出错, 哪位高手能否帮忙看看问题在哪里? 代码如下: package com.package2;
/**
* Function: 测试堆排序
*/
import java.util.*;
public class SortMethod {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//QuickSort st=new QuickSort(); //递归时: 3千万,6s; 1亿,20s; 非递归时: 3千万,11s; 1亿,36s
//MergeSort st=new MergeSort(); //非递归时: 3千万,5s; 1亿,15s; 递归时: 3千万,7s; 1亿,26s;
HeapSort st = new HeapSort();
TestSort ts=new TestSort();
//int size=11; boolean debug=false;
int size=8970; boolean debug=true; //debug=true时仅打印排序开始与结束时间,不打印排序过程
int arr[]=new int[size];
for(int i=0;i<size;i++) arr[i]=(int)(Math.random()*10000); //生成测试数据
ts.process(debug, st, arr);
}
}
class TestSort{
public void process(boolean debug, Sort sort, int[] arr){
sort.setArr(arr);
sort.print(debug);
sort.sort(debug);
sort.print(debug);
}
}
interface Sort{
public void setArr(int[] arr);
public void print(boolean debug);
public void printSystime(boo
|