33
44// left is the left index for the interval
55// right is the right index for the interval
6- // k is the desired index value, where array [k] is the (k+1)th smallest element when left = 0
7- void ipartition (int array [],int left ,int right ,int k ,Func_int cmp ){
6+ // k is the desired index value, where obj [k] is the (k+1)th smallest element when left = 0
7+ void ipartition (int obj [],int left ,int right ,int k ,Func_int cmp ){
88 int tmp ;
99 while (right > left ) {
1010 // Use select recursively to sample a smaller set of size s
@@ -18,28 +18,28 @@ void ipartition(int array[],int left,int right,int k,Func_int cmp){
1818 double sd = 0.5 * sqrt (z * s * (n - s )/n ) * sgn (i - n /2 );
1919 int newLeft = max (left , int (k - i * s /n + sd ));
2020 int newRight = min (right , int (k + (n - i ) * s /n + sd ));
21- ipartition (array , newLeft , newRight , k ,cmp );
21+ ipartition (obj , newLeft , newRight , k ,cmp );
2222 }
2323 // partition the elements between left and right around t
24- int t = array [k ] ;
24+ int t = obj [k ] ;
2525 int i = left ;
2626 int j = right ;
27- swap (array [left ] , array [k ]);
28- if (array [right ] > t ) {
29- swap (array [right ] , array [left ]);
27+ swap (obj [left ] , obj [k ]);
28+ if (obj [right ] > t ) {
29+ swap (obj [right ] , obj [left ]);
3030 }
3131 while (i < j ) {
32- swap (array [i ] , array [j ]);
32+ swap (obj [i ] , obj [j ]);
3333 ++ i ;
3434 -- j ;
35- for (;cmp (array [i ],t ) < 0 ;++ i );
36- for (;cmp (array [j ],t ) > 0 ;-- j );
37- if (cmp (array [left ] , t )== 0 ) {
38- swap (array [left ] , array [j ]);
35+ for (;cmp (obj [i ],t ) < 0 ;++ i );
36+ for (;cmp (obj [j ],t ) > 0 ;-- j );
37+ if (cmp (obj [left ] , t )== 0 ) {
38+ swap (obj [left ] , obj [j ]);
3939 }
4040 else {
4141 ++ j ;
42- swap (array [j ] , array [right ]);
42+ swap (obj [j ] , obj [right ]);
4343 }
4444 // Adjust left and right towards the boundaries of the subset
4545 // containing the (k - left + 1)th smallest element.
@@ -53,8 +53,8 @@ void ipartition(int array[],int left,int right,int k,Func_int cmp){
5353
5454// left is the left index for the interval
5555// right is the right index for the interval
56- // k is the desired index value, where array [k] is the (k+1)th smallest element when left = 0
57- void dpartition (double array [],int left ,int right ,int k ,Func_double cmp ){
56+ // k is the desired index value, where obj [k] is the (k+1)th smallest element when left = 0
57+ void dpartition (double obj [],int left ,int right ,int k ,Func_double cmp ){
5858 double tmp ;
5959 while (right > left ) {
6060 // Use select recursively to sample a smaller set of size s
@@ -68,28 +68,28 @@ void dpartition(double array[],int left,int right,int k,Func_double cmp){
6868 double sd = 0.5 * sqrt (z * s * (n - s )/n ) * sgn (i - n /2 );
6969 int newLeft = max (left , int (k - i * s /n + sd ));
7070 int newRight = min (right , int (k + (n - i ) * s /n + sd ));
71- dpartition (array , newLeft , newRight , k ,cmp );
71+ dpartition (obj , newLeft , newRight , k ,cmp );
7272 }
7373 // partition the elements between left and right around t
74- double t = array [k ] ;
74+ double t = obj [k ] ;
7575 int i = left ;
7676 int j = right ;
77- swap (array [left ] , array [k ]);
78- if (array [right ] > t ) {
79- swap (array [right ] , array [left ]);
77+ swap (obj [left ] , obj [k ]);
78+ if (obj [right ] > t ) {
79+ swap (obj [right ] , obj [left ]);
8080 }
8181 while (i < j ) {
82- swap (array [i ] , array [j ]);
82+ swap (obj [i ] , obj [j ]);
8383 ++ i ;
8484 -- j ;
85- for (;cmp (array [i ],t ) < 0 ;++ i );
86- for (;cmp (array [j ],t ) > 0 ;-- j );
87- if (cmp (array [left ] , t )== 0 ) {
88- swap (array [left ] , array [j ]);
85+ for (;cmp (obj [i ],t ) < 0 ;++ i );
86+ for (;cmp (obj [j ],t ) > 0 ;-- j );
87+ if (cmp (obj [left ] , t )== 0 ) {
88+ swap (obj [left ] , obj [j ]);
8989 }
9090 else {
9191 ++ j ;
92- swap (array [j ] , array [right ]);
92+ swap (obj [j ] , obj [right ]);
9393 }
9494 // Adjust left and right towards the boundaries of the subset
9595 // containing the (k - left + 1)th smallest element.
@@ -101,11 +101,11 @@ void dpartition(double array[],int left,int right,int k,Func_double cmp){
101101 }
102102}
103103
104- int inth (int array [],int k ,int left ,int right , Func_int cmp ){
105- ipartition (array ,left ,right ,k ,cmp );
106- return array [k - left + 1 ];
104+ int inth (int obj [],int k ,int left ,int right , Func_int cmp ){
105+ ipartition (obj ,left ,right ,k ,cmp );
106+ return obj [k - left + 1 ];
107107}
108- double dnth (double array [],int k ,int left ,int right , Func_double cmp ){
109- dpartition (array ,left ,right ,k ,cmp );
110- return array [k - left + 1 ];
108+ double dnth (double obj [],int k ,int left ,int right , Func_double cmp ){
109+ dpartition (obj ,left ,right ,k ,cmp );
110+ return obj [k - left + 1 ];
111111}
0 commit comments