int main(void) { int n = 10000000; clock_t begin, end; item_t *a = malloc(n * sizeof *a); item_t *b = malloc(n * sizeof *b); for_each(a, a + n, init); memcpy(b, a, n * sizeof *a); begin = clock(); mergesortBU(a, 0, n - 1); end = clock(); printf("Bottom up cost: %.2f sec\n", (double)(end - begin)/CLOCKS_PER_SEC); begin = clock(); mergesortTD(b, 0, n - 1); end = clock(); printf("Top down cost: %.2f sec\n", (double)(end - begin)/CLOCKS_PER_SEC); if (memcmp(a, b, n * sizeof *a) == 0) { printf("Yes\n"); } else { printf("No\n"); /*for_each(a, a + n, print); putchar('\n');*/ /*for_each(b, b + n, print); putchar('\n');*/ } free(a); free(b); return 0; }
main (int argc, char *argv[]) { int i; int array[] = {82, 49, 70, 83, 68, 44, 94, 40, 32, 10, 99, 59}; //don't forget to update LEN when this array is modified if (argc == 1) Mergesort(array, LEN); else if (argv[1][1] == 'b') mergesortBU(array, LEN); else printf("Illegal option.\n"); for (i = 0; i < LEN; i++) printf("%d ", array[i]); printf("\n"); return 0; }