What's wrong (quicksort)?

package practice;

import java.util.Arrays;
import java.util.Random;

public class Practice {

 public static void main(String[] args) {
 int[] array = {1, 0, 5, 100, 7, 32, 8, 40, 9, 1, 10};
System.out.println(Arrays.toString(array));

 QuickSort.quickSort(array, 0, array.length - 1);
System.out.println(Arrays.toString(array));
}
}

class QuickSort {

 public static void quickSort(int[] array, int low, int high) {
 Random rand = new Random();

 int L = low;
 int R = high;
 int diff = high - low;

 //Took proizvolnoi El-NT of the random index and the array
 int separator = array[low + rand.nextInt(diff + 1)];//[low;high] on a SEGMENT!!!

 //Parameters is entered correctly?
 if (low >= high) {
return;
}

 while (L <= R) {
 while (array[L] < separator) {
L++;
}
 while (array[R] > separator) {
--R;
}

 if (L <= R) {
 swap(array, L, R);
L++;
--R;
}

}

 quickSort(array, low, R);
 quickSort(array, L, high);
}

 public static void swap(int[] array, int x, int y) {
 int tmp = array[x];
 array[x] = array[y];
 array[y] = tmp;
}
}


Works 1 out of 10 only varici works, and all otsalnoe says error, why?
March 25th 20 at 13:35
1 answer
March 25th 20 at 13:37
Solution
check low <= high should be in the beginning

Find more questions by tags AlgorithmsJava