# 快速排序的问题

0

`int[] arr=new int[]{5,4,1,9,2,8,3,6,7,11,40,19,100,56,78,90,23,43,49,54,48,1,2,0,6,255,25,07,12,123,25,12,15,356,1,6468,154,125,1245,561};    `

``` 1     public int[] QuickSort(int[] arr)
2     {
3         return QuickSort(arr,0,arr.length-1);
4     }
5     private int[] QuickSort(int[] arr,int s,int e)
6     {
7         if (s<e )
8         {
9             int q=partition(arr,s,e);
10             QuickSort(arr, s, q-1);
11             QuickSort(arr, q, e);
12         }
13         return arr;
14     }
15     private int partition(int[] arr, int s, int e)
16     {
17         int i=s,
18                 tmp=0,
19                 j=s-1,
20                 ex=arr[e];
21         for(;i<e;i++)
22         {
23             if(arr[i]<ex)
24             {
25                 j++;
26                 tmp=arr[j];
27                 arr[j]=arr[i];
28                  arr[i]=tmp;
29             }
30         }
31
32         tmp=arr[j+1];
33         arr[j+1]=arr[e];
34         arr[e]=tmp;
35         return j+1;
36     }```

`Exception in thread "main" java.lang.StackOverflowError`
Lucien! | 菜鸟二级 | 园豆：371

0

QuickSort(arr, s, q-1);

QuickSort(arr, q, e);  应改为QuickSort(arr, q-1, e);自己大意了

Lucien! | 菜鸟二级 |园豆：371 | 2015-04-19 10:43

您需要登录以后才能回答，未注册用户请先注册