標籤:
被導師派出差加上之前的大摩的面試,兩周的時間都在飛機或者火車上,弄的回到學校浮躁,狀態不是很好。
調整狀態最好的辦法就是去做了,今天下午寫了一下,一直不願意寫的快速排序演算法,分享一下~
public class QuickSort { /** * @param args */ public static void main(String[] args) { QuickSort sort = new QuickSort(); int[] nums = {2,3,3,3,1,2,2,2}; sort.quickSort(nums, 0, nums.length - 1); for(int num: nums) System.out.print(num+" "); } public void quickSort(int[] nums, int left, int right) { if(left < right) { int index = partition(nums, left, right); quickSort(nums, left, index - 1); quickSort(nums, index + 1, right); } } public int partition(int[] nums, int left, int right) { int key = nums[left]; int low = left; int high = right; while(low < high) { while(low < high && nums[high] >= key) high--; nums[low] = nums[high]; while(low < high && nums[low] < key ) low++; nums[high] = nums[low]; } nums[low] = key; return low; }}
View Code
出差回來--快速排序