diff options
Diffstat (limited to 'numsort.c')
-rw-r--r-- | numsort.c | 94 |
1 files changed, 33 insertions, 61 deletions
@@ -25,24 +25,16 @@ ** Not so; the routine returns # of iterations per sec. */ -void DoNumSort(void) -{ -SortStruct *numsortstruct; /* Local pointer to global struct */ -long *arraybase; /* Base pointers of array */ -long accumtime; /* Accumulated time */ -double iterations; /* Iteration counter */ -char *errorcontext; /* Error context string pointer */ -int systemerror; /* For holding error codes */ +void DoNumSort(void) { + /* Error context string pointer */ + const char *errorcontext = "CPU:Numeric Sort"; + /* Local pointer to global struct */ + SortStruct * numsortstruct = &global_numsortstruct; -/* -** Link to global structure -*/ -numsortstruct=&global_numsortstruct; - -/* -** Set the error context string. -*/ -errorcontext="CPU:Numeric Sort"; + long accumtime; /* Accumulated time */ + double iterations; /* Iteration counter */ + long *arraybase; /* Base pointers of array */ + int systemerror; /* For holding error codes */ /* ** See if we need to do self adjustment code. @@ -105,8 +97,8 @@ else ** All's well if we get here. Repeatedly perform sorts until the ** accumulated elapsed time is greater than # of seconds requested. */ -accumtime=0L; -iterations=(double)0.0; +accumtime = 0L; +iterations = 0.0; do { accumtime+=DoNumSortIteration(arraybase, @@ -127,11 +119,6 @@ numsortstruct->sortspersec=iterations * if(numsortstruct->adjust==0) numsortstruct->adjust=1; -#ifdef DEBUG -if (numsort_status==0) printf("Numeric sort: OK\n"); -numsort_status=0; -#endif -return; } /*********************** @@ -167,21 +154,6 @@ for(i=0;i<numarrays;i++) ** Get elapsed time */ elapsed=StopStopwatch(elapsed); -#ifdef DEBUG -{ - for(i=0;i<arraysize-1;i++) - { /* - ** Compare to check for proper - ** sort. - */ - if(arraybase[i+1]<arraybase[i]) - { printf("Sort Error\n"); - numsort_status=1; - break; - } - } -} -#endif return(elapsed); } @@ -264,29 +236,29 @@ return; ** Peforms the sift operation on a numeric array, ** constructing a heap in the array. */ -static void NumSift(long *array, /* Array of numbers */ - unsigned long i, /* Minimum of array */ - unsigned long j) /* Maximum of array */ +static void NumSift(long *array,/* Array of numbers */ + unsigned long i, /* Minimum of array */ + unsigned long j) /* Maximum of array */ { -unsigned long k; -long temp; /* Used for exchange */ + unsigned long k; + unsigned long temp; /* Used for exchange */ -while((i+i)<=j) -{ - k=i+i; - if(k<j) - if(array[k]<array[k+1L]) - ++k; - if(array[i]<array[k]) - { - temp=array[k]; - array[k]=array[i]; - array[i]=temp; - i=k; - } - else - i=j+1; -} -return; + while ( ( i + i ) <= j ) { + k = i + i; + if ( k < j ) { + if ( array[k] < array[k+1L] ) { + ++k; + } + } + + if ( array[i] < array[k] ) { + temp = array[k]; + array[k] = array[i]; + array[i] = temp; + i = k; + } else { + i = j + 1; + } + } } |