Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MyPackage;
- import org.openjdk.jmh.annotations.*;
- import java.util.Arrays;
- import java.util.concurrent.TimeUnit;
- public class QuickSort {
- public void quickSort(int[] array, int low, int high) {
- if (array.length == 0)
- return;
- if (low >= high)
- return;
- int middle = low + (high - low) / 2;
- int opora = array[middle];
- int i = low, j = high;
- while (i <= j) {
- while (array[i] < opora) {
- i++;
- }
- while (array[j] > opora) {
- j--;
- }
- if (i <= j) {//меняем местами
- int temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- i++;
- j--;
- }
- }
- if (low < j)
- quickSort(array, low, j);
- if (high > i)
- quickSort(array, i, high);
- }
- public void ArraySort(){
- var array = new int[1000];
- for (int i = 0; i < 1000; i++)
- array[i] = 1000 - i;
- quickSort(array, 0, 999);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement