/*Translated by FOR_C, v3.4.2 (-), on 07/09/115 at 08:33:14 */ /*FOR_C Options SET: ftn=u io=c no=p op=aimnv pf=,p_insort s=dbov str=l x=f - prototypes */ #include #include "fcrt.h" #include #include #include "p_insort.h" /*>> 1990-02-09 DRINSORT Snyder Initial code. * * Test driver for INSORT. * * Construct an array of 1000 random numbers using SRANUA. * Sort it using INSORT. * Check whether it is in order. * */ /* COMMON translations */ struct t_rcom { long int ncomp; float r[1000-(1)+1]; } rcom; /* end of COMMON translations */ int main( ) { LOGICAL32 ok; long int l[1000-(1)+1], l1, ls; float prev; /* Generate 1000 random numbers */ sranua( rcom.r, 1000 ); /* Sort them using INSORT. */ rcom.ncomp = 0; insort( compar, 1000, l, &l1 ); ls = l1; /* Check the order. */ ok = TRUE; prev = -1.0; L_10: if (l1 != 0) { if (rcom.r[l1-(1)] < prev) ok = FALSE; prev = rcom.r[l1-(1)]; l1 = l[l1-(1)]; goto L_10; } /* Convert l to a permutation vector. */ pvec( l, ls ); /* Check the order again. */ for (ls = 2; ls <= 1000; ls++) { if (rcom.r[l[ls-(1)]-(1)] < rcom.r[l[ls - 1-(1)]-(1)]) ok = FALSE; } /* Print the results. */ if (ok) { printf(" INSORT succeeded using%6ld compares\n", rcom.ncomp); } else { printf("INSORT failed\n"); } exit(0); } /* end of function */ long /*FUNCTION*/ compar( long i, long j) { long int compar_v; /* Determine the relative order of R(I) and R(J), where R is in * the common block /RCOM/. Return -1 if R(I) should preceed R(J) * in the sorted order, +1 if R(I) should follow R(J), and 0 * otherwise. * */ rcom.ncomp += 1; switch (SARITHIF(rcom.r[i-(1)] - rcom.r[j-(1)])) { case -1: goto L_10; case 0: goto L_20; case 1: goto L_30; } L_10: compar_v = -1; return( compar_v ); L_20: compar_v = 0; return( compar_v ); L_30: compar_v = 1; return( compar_v ); } /* end of function */