Когда я пытаюсь отсортировать мой массив самолетов по номеру полета, я ожидаю, что он покажет приоритет самолетов по порядку.Пример: Самолет A Приоритет: 1, Самолет B Приоритет: 2 Самолет C Приоритет: 3 Самолет D Приоритет: 4 Самолет E Приоритет: 5
Но мой вид продолжает повторять тот же приоритет, что и Самолет A Приоритет: 1 Самолет BПриоритет: 1 ... Etc
Я пытался просто заменить заполнитель int на Airplanes (имя массива, содержащего самолеты). Я делал это раньше, но что-то упустил?
// Java program for implementation of QuickSort
import java.util.*;
class IterativeQuickSort
{
/* This function takes last element as pivot,
places the pivot element at its correct
position in sorted array, and places all
smaller (smaller than pivot) to left of
pivot and all greater elements to right
of pivot */
static int partition(Airplane[] arr, int low, int high)
{
Airplane pivot = arr[high];
int i = (low-1); // index of smaller element
for (int j=low; j<=high-1; j++)
{
// If current element is smaller than or
// equal to pivot
if (arr[j].compareTo(pivot) <= 0)
{
i++;
// swap arr[i] and arr[j]
Airplane temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
// swap arr[i+1] and arr[high] (or pivot)
Airplane temp = arr[i+1];
arr[i+1] = arr[high];
arr[high] = temp;
return i+1;
}
/* The main function that implements QuickSort()
arr[] --> Array to be sorted,
low --> Starting index,
high --> Ending index */
static void sort(Airplane[] arr, int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[pi] is
now at right place */
int pi = partition(arr, low, high);
// Recursively sort elements before
// partition and after partition
sort(arr, low, pi-1);
sort(arr, pi+1, high);
}
}
}