0
Я до сих пор держу волосы до сих пор, потому что я не могу думать об анимации для этого алгоритма сортировки в java, и я все равно плачу в углу каждый раз, когда я пытаюсь это сделать. Это мой код, можете ли вы, пожалуйста, помочь мне сделать анимацию здесь?Я не могу сделать эту анимацию Heapsort
public static final int max = 11;
public static void main(String[] args) {
int[] toSortArray = new int[max];
toSortArray[0] = 0;
for (int i = 1; i < max; i++) {
toSortArray[i] = (int) (Math.random() * 100);
toSortArray[0]++;
int index = i;
while (toSortArray[index/2] < toSortArray[index] && (index/2) != 0) {
int temp = toSortArray[index/2];
toSortArray[index/2] = toSortArray[index];
toSortArray[index] = temp;
index = index/2;
}
}
System.out.println("The array to be sorted is:");
for (int i = 0; i < max; i++) {
System.out.print(" | " + toSortArray[i]);
}
System.out.println(" | ");
while (toSortArray[0] > 0) {
int temp = toSortArray[1];
toSortArray[1] = toSortArray[toSortArray[0]];
toSortArray[toSortArray[0]] = temp;
for (int i = 1; i < toSortArray[0]; i++) {
int index = i;
while (toSortArray[index/2] < toSortArray[index] && (index/2) != 0) {
int temp1 = toSortArray[index/2];
toSortArray[index/2] = toSortArray[index];
toSortArray[index] = temp1;
index = index/2;
}
}
toSortArray[0]--;
}
System.out.println("The sorted array is: ");
for (int i = 0; i < max; i++) {
System.out.print(" | " + toSortArray[i]);
}
System.out.println(" | ");
}