int main() { read(); cocktail(); write(); return(0); };
int main() { int i, n; int * arr; scanf("%d", &n); arr = (int*) malloc(n*sizeof(int)); for (i = 0; i < n; i++) scanf("%d", arr+i); cocktail(arr, n); for (i = 0; i < n-1; i++) printf("%d,", arr[i]); printf("%d\n", arr[i]); free(arr); return 0; }
int main (int argc, char ** argv) { int dmin = 0; int dmax = 1000; int nstart = 20; int nmax = 30000; double nfac = 1.2; double nd; int * data; int * dup; /* Allocate one big random input data array. For varying the and making sure we always start with random input, we will use a duplicate (with just the first N entries) at each iteration. */ printf ("# generating input data (this can take a while...)\n"); fflush (stdout); data = random_array (dmin, dmax, nmax); dup = malloc (nmax * sizeof(int)); if (NULL == dup) { err (EXIT_FAILURE, __FILE__": %s: malloc", __func__); } printf ("################################################\n" "#\n" "# Cocktail sort runtime measurements\n" "#\n" "# column 1: N\n" "# column 2: Random array T [ms]\n" "# column 3: ascended array as input [ms]\n" "# column 4: Descended array as in put [ms]\n" "#\n"); /* Main benchmarking loop. Note that we use a floating point "length" so that we can easily create a geometric series for N. This spaces the sampled array sizes more densely for small N, and for big N (where things usually take much longer) we don't take so many samples (otherwise running the benchmark takes a really long time). */ //int tempnum; for (nd = nstart; nd <= nmax; nd *= nfac) { double temp0 = 0, temp1 = 0, temp2 = 0; int nn; double tstart2, tstop2, tstart1 , tstop1 , tstart0, tstop0; /* convert the floating point "length" to an integer */ nn = nd; // printf ("%8d", nn); fflush (stdout); /* use a fresh duplicate from the random input data */ memcpy (dup, data, nn * sizeof(int)); //=========== random input =================== tstart0 = clockms (); cocktail (dup, nn); tstop0 = clockms (); temp0 = tstop0 - tstart0; //========== Asc sort as input =============== bubbAsc (dup, nn); tstart1 = clockms (); cocktail (dup, nn); tstop1 = clockms (); temp1 = tstop1 - tstart1; //=========== Des sort as input ============== bubbDes (dup, nn); tstart2 = clockms (); cocktail (dup, nn); tstop2 = clockms (); temp2 = tstop2 - tstart2; // printf (" %8g", tstop - tstart); printf (" %8d %8g %8g %8g\n",nn,temp0, temp1 ,temp2); } /* End of the program. */ free (data); free (dup); return 0; }