美文网首页
JAVA语言表达 快速排序算法

JAVA语言表达 快速排序算法

作者: 笨笨快跑 | 来源:发表于2017-08-19 22:44 被阅读0次

    package mysql;

    /**

    * Created by Zhangshunyu on 2017/8/19.

    */

    public class test {

    public static void main (String[] args) {

    int[] testArray = {3,5,8,1,2,9,0,4};

    quickSort(testArray, 0, testArray.length - 1);

    for (int i : testArray) {

    System.out.print(i);

    }

    }

    public static void quickSort(int[] array, int low, int high) {

    int lowTag = low;

    int highTag = high;

    int key = array[low];

    while (lowTag < highTag) {

    while (highTag > lowTag && array[highTag] > key) {

    highTag--;

    }

    int tempSmall = array[highTag];

    array[highTag] = array[lowTag];

    array[lowTag] = tempSmall;

    lowTag++;

    while (lowTag < highTag && array[lowTag] < key) {

    lowTag++;

    }

    int tempBig = array[lowTag];

    array[lowTag] = array[highTag];

    array[highTag] = tempBig;

    highTag--;

    }

    if (low < lowTag) {

    quickSort(array, low, lowTag - 1);

    }

    if (high > highTag) {

    quickSort(array, highTag + 1, high);

    }

    }

    }

    相关文章

      网友评论

          本文标题:JAVA语言表达 快速排序算法

          本文链接:https://www.haomeiwen.com/subject/rgsxdxtx.html