super();\r
}\r
\r
- public void serializedSort(int A[]) {\r
-\r
- if (A.length <= QUICK_SIZE) {\r
- quickSort(A, 0, A.length - 1);\r
- } else {\r
-\r
- int q = A.length / 4;\r
+ public void runWorkAndTest() {\r
+ sese run{\r
+ int output[]=sort(input, 0, input.length);\r
+ }\r
+ sese test{\r
+ checkSorted(output);\r
+ }\r
+ }\r
\r
- int idxs0 = q;\r
- int idxs1 = 2 * q;\r
- int idxs2 = 3 * q;\r
\r
- int size0 = idxs0;\r
- int size1 = idxs1 - idxs0;\r
- int size2 = idxs2 - idxs1;\r
- int size3 = A.length - idxs2;\r
+ public int[] serializedSort(int A[], int low, int high) {\r
+ if(A.length<=SERIALIZED_CUT_OFF){\r
+ return serializedSort(A, low, high);\r
+ }else{\r
+ if (A.length <= QUICK_SIZE) {\r
+ int[] R=new int[high-low];\r
+ int max=R.length;\r
+ int j=low;\r
+ for(int i=0;i<max;i++) {\r
+ R[i]=A[j++];\r
+ }\r
+ quickSort(R, 0, R.length);\r
+ return R;\r
+ } else {\r
+ int q = A.length / 4;\r
+ \r
+ int idxs0 = q;\r
+ int idxs1 = 2 * q;\r
+ int idxs2 = 3 * q;\r
+ \r
+ int[] A_quarters0 = serializedSort(A, 0, idxs0);\r
+ int[] A_quarters1 = serializedSort(A, idxs0, idxs1);\r
+ int[] A_quarters2 = serializedSort(A, idxs1, idxs2);\r
+ int[] A_quarters3 = serializedSort(A, idxs2, A.length);\r
\r
- int[] A_quarters0 = new int[size0];\r
- int[] A_quarters1 = new int[size1];\r
- int[] A_quarters2 = new int[size2];\r
- int[] A_quarters3 = new int[size3];\r
+ int[] R=new int[high-low];\r
\r
- for (int i = 0; i < idxs0; i++) {\r
- A_quarters0[i] = A[i];\r
+ merge(A_quarters0, A_quarters1, A_quarters2, A_quartes3, R);\r
+ return R;\r
}\r
- for (int i = idxs0; i < idxs1; i++) {\r
- A_quarters1[i - idxs0] = A[i];\r
- }\r
- for (int i = idxs1; i < idxs2; i++) {\r
- A_quarters2[i - idxs1] = A[i];\r
- }\r
- int amax=A.length;\r
- for (int i = idxs2; i < amax; i++) {\r
- A_quarters3[i - idxs2] = A[i];\r
- }\r
-\r
- int h1 = A_quarters0.length + A_quarters1.length;\r
- int h2 = A_quarters2.length + A_quarters3.length;\r
- int[] B_halves0 = new int[h1];\r
- int[] B_halves1 = new int[h2];\r
-\r
- serializedSort(A_quarters0);\r
- serializedSort(A_quarters1);\r
- serializedSort(A_quarters2);\r
- serializedSort(A_quarters3);\r
-\r
- sequentialMerge(A_quarters0, A_quarters1, B_halves0);\r
- sequentialMerge(A_quarters2, A_quarters3, B_halves1);\r
- sequentialMerge(B_halves0, B_halves1, A);\r
-\r
}\r
-\r
}\r
\r
- public void sort(int A[]) {\r
- \r
+ public int[] sort(int A[], int low, int high) {\r
if(A.length<=SERIALIZED_CUT_OFF){\r
- serializedSort(A);\r
+ return serializedSort(A, low, high);\r
}else{\r
if (A.length <= QUICK_SIZE) {\r
- quickSort(A,0,A.length-1);\r
+ int[] R=new int[high-low];\r
+ int max=R.length;\r
+ int j=low;\r
+ for(int i=0;i<max;i++) {\r
+ R[i]=A[j++];\r
+ }\r
+ quickSort(R, 0, R.length);\r
+ return R;\r
} else {\r
- \r
- int q = A.length / 4;\r
+ int q = A.length / 4;\r
\r
int idxs0 = q;\r
int idxs1 = 2 * q;\r
int idxs2 = 3 * q;\r
- \r
- int size0 = idxs0;\r
- int size1 = idxs1 - idxs0;\r
- int size2 = idxs2 - idxs1;\r
- int size3 = A.length - idxs2;\r
- \r
- int[] A_quarters0 = new int[size0];\r
- int[] A_quarters1 = new int[size1];\r
- int[] A_quarters2 = new int[size2];\r
- int[] A_quarters3 = new int[size3];\r
- \r
- for (int i = 0; i < idxs0; i++) {\r
- A_quarters0[i] = A[i];\r
- }\r
- for (int i = idxs0; i < idxs1; i++) {\r
- A_quarters1[i - idxs0] = A[i];\r
- }\r
- for (int i = idxs1; i < idxs2; i++) {\r
- A_quarters2[i - idxs1] = A[i];\r
- }\r
- int amax=A.length;\r
- for (int i = idxs2; i < amax; i++) {\r
- A_quarters3[i - idxs2] = A[i];\r
- }\r
-\r
- int h1 = A_quarters0.length+A_quarters1.length;\r
- int h2 = A_quarters2.length+A_quarters3.length;\r
- \r
+ \r
sese p1{\r
- sort(A_quarters0);\r
+ int[] A_quarters0 = sort(A, 0, idxs0);\r
}\r
sese p2{\r
- sort(A_quarters1);\r
+ int[] A_quarters1 = sort(A, idxs0, idxs1);\r
}\r
sese p3{\r
- sort(A_quarters2);\r
+ int[] A_quarters2 = sort(A, idxs1, idxs2);\r
}\r
//don't spawn off sese for last one...\r
- sort(A_quarters3);\r
- \r
- merge(A_quarters0, A_quarters1, A_quarters2, A_quartes3, A);\r
+ int[] A_quarters3 = sort(A, idxs2, A.length);\r
+\r
+ int[] R=new int[high-low];\r
+\r
+ merge(A_quarters0, A_quarters1, A_quarters2, A_quartes3, R);\r
+ return R;\r
}\r
}\r
}\r