Advertisement
Vankata17

QuickSortMethods

Jan 15th, 2021
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class QuickSortMethods {
  4.     public static void QuickSort(int[] ARR, int low, int high) {
  5.         if (low < high) {
  6.             int pi = partition(ARR, low, high);
  7.             QuickSort(ARR, low, pi - 1);
  8.             QuickSort(ARR, pi + 1, high);
  9.         }
  10.     }
  11.  
  12.     public static int partition(int[] ARR, int low, int high) {
  13.         int pivot = ARR[high];
  14.         int i = low - 1;
  15.         for (int j = low; j < high; j++) {
  16.             if (ARR[j] < pivot) {
  17.                 //swap
  18.                 i++;
  19.                 int temp = ARR[j];
  20.                 ARR[j] = ARR[i];
  21.                 ARR[i] = temp;
  22.             }
  23.         }
  24.         int temp = ARR[high];
  25.         ARR[high] = ARR[i + 1];
  26.         ARR[i + 1] = temp;
  27.         return i + 1;
  28.     }
  29.  
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement