Doxygen Source Code Documentation
qsort.h File Reference
#include <stdlib.h>
#include <stdio.h>
Go to the source code of this file.
Functions | |
void | isort_sh (int, short *) |
void | qsrec_sh (int, short *, int) |
void | qsort_sh (int, short *) |
void | qsort_partial_sh (int, short *, int) |
int | MCW_inverse_histogram (int, short *, int, short *) |
Function Documentation
|
Definition at line 152 of file thd_winsor.c. Referenced by qsort_partial_sh(), and qsort_sh().
00153 { 00154 register int j , p ; /* array indices */ 00155 register short temp ; /* a[j] holding place */ 00156 register short * a = ar ; 00157 00158 if( n < 2 ) return ; 00159 00160 for( j=1 ; j < n ; j++ ){ 00161 00162 if( a[j] < a[j-1] ){ /* out of order */ 00163 p = j ; 00164 temp = a[j] ; 00165 00166 do{ 00167 a[p] = a[p-1] ; /* now have a[p-1] > temp, so move it up */ 00168 p-- ; 00169 } while( p > 0 && temp < a[p-1] ) ; 00170 00171 a[p] = temp ; /* finally, put temp in its place */ 00172 } 00173 } 00174 } |
|
|
|
Definition at line 146 of file qsort.c. References a, isort_sh(), and qsrec_sh(). Referenced by MCW_inverse_histogram_sh().
|
|
Definition at line 252 of file thd_winsor.c.
|
|
Definition at line 183 of file thd_winsor.c. References a, i, left, QS_STACK, QS_SWAP, and right.
00184 { 00185 register int i , j ; /* scanning indices */ 00186 register short temp , pivot ; /* holding places */ 00187 register short * a = ar ; 00188 00189 int left , right , mst , stack[QS_STACK] ; 00190 00191 /* return if too short (insertion sort will clean up) */ 00192 00193 if( cutoff < 3 ) cutoff = 3 ; 00194 if( n < cutoff ) return ; 00195 00196 /* initialize stack to start with whole array */ 00197 00198 stack[0] = 0 ; 00199 stack[1] = n-1 ; 00200 mst = 2 ; 00201 00202 /* loop while the stack is nonempty */ 00203 00204 while( mst > 0 ){ 00205 right = stack[--mst] ; /* subarray from left -> right */ 00206 left = stack[--mst] ; 00207 00208 i = ( left + right ) / 2 ; /* middle of subarray */ 00209 00210 /* sort the left, middle, and right a[]'s */ 00211 00212 if( a[left] > a[i] ) QS_SWAP( a[left] , a[i] ) ; 00213 if( a[left] > a[right] ) QS_SWAP( a[left] , a[right] ) ; 00214 if( a[i] > a[right] ) QS_SWAP( a[right] , a[i] ) ; 00215 00216 pivot = a[i] ; /* a[i] is the median-of-3 pivot! */ 00217 a[i] = a[right] ; 00218 00219 i = left ; /* initialize scanning */ 00220 j = right ; 00221 00222 /*----- partition: move elements bigger than pivot up and elements 00223 smaller than pivot down, scanning in from ends -----*/ 00224 00225 do{ 00226 for( ; a[++i] < pivot ; ) ; /* scan i up, until a[i] >= pivot */ 00227 for( ; a[--j] > pivot ; ) ; /* scan j down, until a[j] <= pivot */ 00228 00229 if( j <= i ) break ; /* if j meets i, quit */ 00230 00231 QS_SWAP( a[i] , a[j] ) ; 00232 } while( 1 ) ; 00233 00234 /*----- at this point, the array is partitioned -----*/ 00235 00236 a[right] = a[i] ; /* restore the pivot */ 00237 a[i] = pivot ; 00238 00239 if( (i-left) > cutoff ){ stack[mst++] = left ; stack[mst++] = i-1 ; } 00240 if( (right-i) > cutoff ){ stack[mst++] = i+1 ; stack[mst++] = right ; } 00241 00242 } /* end of while stack is non-empty */ 00243 } |