java 排序算法
Posted 燃灯胡同
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 排序算法相关的知识,希望对你有一定的参考价值。
public int get_middle(int[] list, int low, int high){ int tmp = list[low]; while(low < high){ while(low < high && list[high]>tmp){ high --; } list[low] = list[high]; while(low < high && list[low] < tmp){ low ++; } list[high] = list[low]; } list[low] = tmp; return low; } public void quick_sort(int[] list, int low, int high){ int middle = get_middle(list, low, high); quick_sort(list, low, middle-1); quick_sort(list, middle+1, high); } public void use_quick_sort(int[] list){ if (list.length > 1){ quick_sort(list, 0, list.length-1); } } public static void bubble_sort(int[] list) { int temp = 0; for (int i = list.length - 1; i > 0; --i) { for (int j = 0; j < i; ++j) { if (list[j] > list[j + 1]) { temp = list[j + 1]; list[j + 1] = list[j]; list[j] = temp; } } } }
以上是关于java 排序算法的主要内容,如果未能解决你的问题,请参考以下文章