gofound/tests/sort.md

44 lines
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

```
if(low<i)
quickSort(arr,low,i-1);//对左端子数组递归
if(i<high)
quickSort(arr,j+1,high);//对右端子数组递归
if(high<i) //注意,下标值
quickSort(arr,high,i-1);//对左端子数组递归
if(i<low) //注意,下标值
quickSort(arr,i+1,low);
```
```java
public static void quickSort(int[] arr,int high,int low){
int i,j,temp;
i=high;//高端下标
j=low;//低端下标
temp=arr[i];//取第一个元素为标准元素。
while(i<j){//递归出口是 low>=high
while(i<j&&temp>arr[j])//后端比temp小符合降序不管它low下标前移
j--;//while完后指比temp大的那个
if(i<j){
arr[i]=arr[j];
i++;
}
while(i<j&&temp<arr[i])
i++;
if(i<j){
arr[j]=arr[i];
j--;
}
}//while完即第一盘排序
arr[i]=temp;//把temp值放到它该在的位置。
if(high<i) //注意,下标值
quickSort(arr,high,i-1);//对左端子数组递归
if(i<low) //注意,下标值
quickSort(arr,i+1,low);//对右端子数组递归 对比上面例子其实此时i和j是同一下标!!!!!!!!!!!!!
}
```