void some_function() {
int d[] = new int[10];
int e[] = new int[15];
int f[] = new int[20];
int g[] = new int[25];
int h[] = new int[30];
int i[] = new int[35];
int j[] = new int[40];
int k[] = new int[45];
int l[] = new int[50];
int m[] = new int[55];
int n[] = new int[60];
int o[] = new int[65];
int p[] = new int[70];
int q[] = new int[75];
int r[] = new int[80];
int s[] = new int[85];
int t[] = new int[90];
int u[] = new int[95];
int v[] = new int[100];
//Randomly generate int elements of the array
int master_list[][] = {d, e, f, g, h, i, j, k, l, m, n,
o, p, q, r, s, t, u, v};
Random gen = new Random();
int i_array[];
double run_times[][] = new double[19][6];
double start, end, total_time_1, total_time_2, total_time_3;
double comp_1, comp_2, comp_3;
for(int idex = 0; idex < master_list.length; idex++) {
i_array = master_list[idex];
//Randomly generate integers to put in each array
for(int jdex = 0; jdex < master_list[idex].length; jdex++) {
i_array[jdex] = gen.nextInt(10);
}
comp_1 = ((14*(Math.pow(i_array.length, 2)))
+ (i_array.length/2) + 4);
comp_2 = ((14*i_array.length) + 35);
comp_3 = ((19*i_array.length) + 4);
/* This is the part where we begin to print and calculate
data for our report. It begins with caluculating the
run time of each algorithm by calling the system clock
method of System.nanoTime() */
System.out.println("Input size: " + i_array.length);
System.out.println("Run time of Algorithm 1:");
start = System.nanoTime();
driver.algorithm_1(i_array);
end = System.nanoTime();
total_time_1 = end - start;
System.out.println("Total time elapsed: " + total_time_1
+ " milliseconds.");
//We then add this time into the [19][6] matrix.
run_times[idex][0] = total_time_1;
run_times[idex][3] = comp_1;
//The process then repeats for algorithm 2
System.out.println("Run time of Algorithm 2:");
start = System.nanoTime();
driver.algorithm_2(i_array);
end = System.nanoTime();
total_time_2 = end - start;
System.out.println("Total time elapsed: " + total_time_2
+ " milliseconds.");
run_times[idex][1] = total_time_2;
run_times[idex][4] = comp_2;
//Yet again another repitition for algorithm 3
System.out.println("Run time of Algorithm 3:");
start = System.nanoTime();
driver.algorithm_3(i_array);
end = System.nanoTime();
total_time_3 = end - start;
System.out.println("Total time elapsed: " + total_time_3
+ " milliseconds.\n");
run_times[idex][2] = total_time_3;
run_times[idex][5] = comp_3;
}
}
所以整个事情的问题是我正在尝试创建一个大小为run_times [19] [6]的数组,但是,我只得到一个大小为[10] [5]的列表。
因此,该算法采用 int 数组 d - v 并为它们生成随机元素。然后我计算每个算法的运行时间和复杂性(不包括在内)。
运行时数组是这样的: [0][0] = algorithm_1 time [0][1] = algorithm_2 time [0][2] = algorithm_3 time [0][3] = algorithm_1 complex [0][4 ] = algorithm_2 复杂度 [0][5] = algorithm_3 复杂度
复杂度加倍是在 T(n) 递归关系中为 n 插入数组大小。
知道出了什么问题吗?它可以编译并且没有运行时错误。