/*void swap(void** a,void** b){ void* temp; temp = *a; *a = *b; *b = *a; }*/ int main(){ srand(time(0)); int i; int** arr = calloc(sizeof(int*),SIZE); for( i = 0; i < SIZE; i++){ int* n = malloc(sizeof(int)); *n = rand()% 985; arr[i] = n; } for( i = 0; i < SIZE; i++){ printf("element %4d at address %p is %4d\n",i,arr[i],*arr[i]); } printf("sorting......\n"); gnomesort(arr,SIZE,compare_int); for( i = 0; i < SIZE; i++){ printf("element %4d at address %p is %4d\n",i,arr[i],*arr[i]); } }
int main (int argc, char** argv) { double array[ARRAY_SIZE]; int i = 0, cnt = -1; srand (time (NULL)); #if !RANDOM printf ("Please input a list of numbers to sort... "); while (scanf ("%lf", &(array[i])) > 0) { //malloc(1000); //memmove(malloc((i + 2)*sizeof(double)), &array, (i + 1)*sizeof(double)); //printf ("%lf\n", array[i]); i++; } #else double rnd; while (i < RANDOM) { rnd = LOWER + (rand () / (UPPER - LOWER)); //printf ("%0.1f ", rnd); array[i++] = rnd; } //printf ("\n\n"); #endif #if TYPE == 0 cnt = insertion (&array, i); #elif TYPE == 1 cnt = quicksort (&array, i); #elif TYPE == 2 cnt = gnomesort (&array, i); #endif printf ("The contents of the array are: "); int j; for (j = 0; j < i; j++) { printf ("%0.1lf ", array[j]); } printf ("\nIt took this many swaps: %d", cnt); //printf ("\nIt took this many compares: %d", comp); return (EXIT_SUCCESS); }