如何在java中保存矩阵中快速排序的每个步骤?
我无法保存排序quickstep的每个步骤。我写了这封信,但它没有打印任何东西。。。 我想让javafx应用程序具有这样一个特性:我可以按下下一步按钮,它会做出一步一步后退的按钮。因此,我将运行整个快速排序,并将所有迭代保存到矩阵,稍后我将显示矩阵bz的每一列,单击“下一步”和“上一步”。所以我想从一开始就开始,但我一直在努力节省时间 编辑: 另外,我知道每一步都应该打印矩阵,我不想这样,我会在以后添加一些条件如何在java中保存矩阵中快速排序的每个步骤?,java,matrix,quicksort,Java,Matrix,Quicksort,我无法保存排序quickstep的每个步骤。我写了这封信,但它没有打印任何东西。。。 我想让javafx应用程序具有这样一个特性:我可以按下下一步按钮,它会做出一步一步后退的按钮。因此,我将运行整个快速排序,并将所有迭代保存到矩阵,稍后我将显示矩阵bz的每一列,单击“下一步”和“上一步”。所以我想从一开始就开始,但我一直在努力节省时间 编辑: 另外,我知道每一步都应该打印矩阵,我不想这样,我会在以后添加一些条件 public class QS { public static void m
public class QS {
public static void main(String[] args) {
int[] x = { 9, 2, 4, 7, 3, 7, 10 };
System.out.println(Arrays.toString(x));
final int [] [] test = {
{1,2,3},
{4,5,6},
{7,8,9}
};
//for (int p = 0; p < test.length; p++){
// for (int k = 0; k < test[p].length; k++){
// System.out.print(test[p][k] + " ");
// }
// System.out.println();
//}
int low = 0;
int high = x.length - 1;
quickSort(x, low, high);
System.out.println(Arrays.toString(x));
int [] [] save = new int [9] [x.length];
}
public static void quickSort(int[] arr, int low, int high) {
if (arr == null || arr.length == 0)
return;
if (low >= high)
return;
// pick the pivot
int middle = low + (high - low) / 2;
int pivot = arr[middle];
// make left < pivot and right > pivot
int i = low, j = high;
while (i <= j) {
while (arr[i] < pivot)
i++;
while (arr[j] > pivot)
j--;
if (i <= j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}
int[][] save = new int[9][arr.length];
int index = 0;
// recursively sort two sub parts
if (low < j)
quickSort(arr, low, j);
for (int h=0; h>arr.length+1; h++){
save [index] [h] = arr [h];
index++;
for (int e = 0; e < save.length; e++) {
for (int f = 0; f < save[e].length; f++) {
System.out.print(save[e][f] + " ");
}
System.out.println();
}
}
if (high > i)
quickSort(arr, i, high);
for (int h=0; h>arr.length+1; h++){
save [index] [h] = arr [h];
index++;
for (int e = 0; e < save.length; e++) {
for (int f = 0; f < save[e].length; f++) {
System.out.print(save[e][f] + " ");
}
System.out.println();
}
}
}
}
公共类QS{
公共静态void main(字符串[]args){
int[]x={9,2,4,7,3,7,10};
System.out.println(Arrays.toString(x));
最终整数[][]测试={
{1,2,3},
{4,5,6},
{7,8,9}
};
//对于(int p=0;p=高)
返回;
//选择支点
int middle=低+(高-低)/2;
int pivot=arr[中间];
//使左<枢轴和右>枢轴
int i=低,j=高;
而(我)
j--;
if(i arr.length+1;h++){
保存[index][h]=arr[h];
索引++;
for(int e=0;ei)
快速排序(arr、i、高);
对于(int h=0;h>arr.length+1;h++){
保存[index][h]=arr[h];
索引++;
for(int e=0;e
在for循环中,例如:
for (int h=0; h>arr.length+1; h++){/*code*/}
据推测,它应该是一个小于符号:
for (int h=0; h<arr.length+1; h++){/*code*/}
for(int h=0;hfor循环中,如以下循环:
for (int h=0; h>arr.length+1; h++){/*code*/}
据推测,它应该是一个小于符号:
for (int h=0; h<arr.length+1; h++){/*code*/}
用于(int h=0;hHi Ondra!你能把你的问题简化成一个小例子吗?你的问题似乎更多的是关于你的特定代码,而不是编程结构、库或技术,而Stackoverflow问题在小而具体的时候最容易回答。嗨Ondra!你能把你的问题简化成一个小例子吗?你的问题出现了更多地关注您的特定代码,而不是编程构造、库或技术,而Stackoverflow问题在小而具体时最容易回答。