By the teacher sent the difference plus before the big Morgan interview, two weeks of time in the plane or train, get back to school impetuous, the state is not very good.
The best way to adjust the state is to do, this afternoon wrote a bit, has been reluctant to write the fast sorting algorithm, share the ~
Public classQuickSort {/** * @paramargs*/ Public Static voidMain (string[] args) {QuickSort sort=NewQuickSort (); int[] Nums = {2,3,3,3,1,2,2,2}; Sort.quicksort (Nums,0, Nums.length-1); for(intnum:nums) System.out.print (Num+" "); } Public voidQuickSort (int[] Nums,intLeftintRight ) { if(Left <Right ) { intindex =partition (Nums, left, right); QuickSort (Nums, left, index-1); QuickSort (nums, index+ 1, right); } } Public intPartitionint[] Nums,intLeftintRight ) { intKey =Nums[left]; intLow =Left ; intHigh =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; returnLow ; }}
View Code
Business trip back--quick sort