Java Quick Sort quickSort(short[] fireZoneInfo, int left, int right)

Here you can find the source of quickSort(short[] fireZoneInfo, int left, int right)

Description

Does a quick sort on the given array

License

Apache License

Declaration


public static void quickSort(short[] fireZoneInfo, int left, int right) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//w  w w.j  a  v  a2s.  c  om
     * Does a quick sort on the given array
     * 
     * @author Hesam 002
     */

    public static void quickSort(short[] fireZoneInfo, int left, int right) {
        int index = partition(fireZoneInfo, left, right);
        if (left < index - 1)
            quickSort(fireZoneInfo, left, index - 1);
        if (index < right)
            quickSort(fireZoneInfo, index, right);
    }

    /**
     * Partitions the array for quick sort
     * 
     * @author Hesam 002
     */
    public static int partition(int arr[], int left, int right) {
        int i = left, j = right;
        int tmp;
        int pivot = arr[(left + right) / 2];

        while (i <= j) {
            while (arr[i] < pivot)
                i++;
            while (arr[j] > pivot)
                j--;
            if (i <= j) {
                tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
                i++;
                j--;
            }
        }
        return i;
    }

    /**
     * Partitions the array for quick sort
     * 
     * @author Hesam 002
     */
    public static int partition(short arr[], int left, int right) {
        int i = left, j = right;
        short tmp;
        int pivot = arr[(left + right) / 2];

        while (i <= j) {
            while (arr[i] < pivot)
                i++;
            while (arr[j] > pivot)
                j--;
            if (i <= j) {
                tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
                i++;
                j--;
            }
        }
        return i;
    }
}

Related

  1. quicksort(int[] source)
  2. quickSort(int[] source)
  3. quickSort(int[] target, int[] coSort)
  4. quickSort(int[] x)
  5. quickSort(int[] x)
  6. quicksort(String a[], int lo0, int hi0)
  7. quickSort(String a[], int lo0, int hi0)
  8. quickSort(String[] str, int low, int high)
  9. quickSort(String[] strings, int begin, int length)