私はどこからでもこのアルゴリズムを見たことがなく、自分でやった.クイックソートがどのように機能するかを見ただけ. 6. または、私が知らない他の問題がある可能性があります。ここにコードがあります-
import java.util.Scanner;
class Main {
public static void main(String[] args) {
System.out.print("Enter number of elements= ");
int x, a[];
Scanner z = new Scanner(System.in);
x = Integer.parseInt(z.next());
a = new int[x];
for(int i = 0; i < x; i++){
System.out.print("Enter element #"+(i+1)+"= ");
a[i] = Integer.parseInt(z.next());
}
QuickSort(a, 0, x-1);
System.out.print("A= ");
for(int i = 0; i < x; i++){
System.out.print(a[i]+" ");
}
}
public static void QuickSort(int a[], int low, int high){
if(low >= high)
return;
int l = low + 1, h = high, flag = 0, temp;
while(l <= h){
if(a[low] >= a[l]){
++l;
++flag;
}
if(a[low] <a [h]){
--h;
++flag;
} else if(flag == 0){
temp = a[l];
a[l] = a[h];
a[h] = temp;
++l;
--h;
}
}
temp = a[low];
a[low] = a[h];
a[h] = temp;
QuickSort(a, low, h-1);
QuickSort(a, h+1, high);
}
}
すべての助けをありがとう。