int main(void) { int array[NUM]; clock_t start, end; double st,bt; //s_sort time,b_sort time initialize(array); disp_array(array); start = clock(); s_sort(array); end = clock(); disp_array(array); st = (double)(end-start)/CLOCKS_PER_SEC; start = clock(); initialize(array); b_sort(array); end = clock(); disp_array(array); bt = (double)(end-start)/CLOCKS_PER_SEC; printf("simple compare:%d\nchange:%d\n",s_co_count,s_ch_count); printf("TIME:%lf\n",st); printf("bubble compare:%d\nchange:%d\n",b_co_count,b_ch_count); printf("TIME:%lf\n",bt); return 0; }
int main(void) { int array[NUM]; initialize(array); disp_array(array); bubble_sort(array); disp_array(array); return 0; }
int main() { int src_array[] = {5,4,5,1,3,2,8,4,2,5,6,1,5,6,9,1,5,4,8}; //int src_array[] = {1,3,5,7,9,8,6,4,2,0}; int len = sizeof(src_array)/sizeof(src_array[0]); int *dst_array = calloc(len, sizeof(int)); disp_array(src_array, len); count_sort(src_array, dst_array, len, 20); disp_array(dst_array, len); free(dst_array); return 0; }
int main(void) { int array[NUM]; initialize(array); disp_array(array); bubble_sort(array); disp_array(array); printf("comp : %d\nswap : %d\n",comp_i,swap_i); return 0; }
int sort(void) { int *arr; arr = malloc(sizeof(int) * (NB_VALUES + 1)); if (!arr) return (ERROR); init_array(arr); disp_array(arr, 0); sort_array(arr); disp_array(arr, 1); return (SUCESS); }
int main(void) { int sort_mode = 1; int sort_by = 1; parameter player[PLAYER]; srand(1); initialize(player); printf("昇順(1) or 降順?(2) : "); scanf("%d",&sort_mode); printf("mode : %d\n",sort_mode); printf("ソート項目の選択\n"); printf("NO\t:\t1\n"); printf("NAME\t:\t2\n"); printf("HP\t:\t3\n"); printf("MP\t:\t4\n"); printf("ATTACK\t:\t5\n"); printf("DEFENCE\t:\t6\n"); printf("input : "); scanf("%d",&sort_by); printf("by : %d\n",sort_by); sort_players(sort_mode,sort_by,player); disp_array(player); return 0; }
int main() { double array1[MAXSIZE],array2[MAXSIZE],array3[MAXSIZE*2]; int size1,size2,location; double value; printf("Enter the 1st array terminated by a CTRL-D:\n"); size1=get_array(array1); printf("\nYou entered these numbers:\n"); disp_array(size1,array1); sort_array(size1,array1); printf("\nIn descending order, these are the number you entered:\n"); disp_array(size1,array1); printf("\n\nEnter the 2nd array terminated by a CTRL-D:\n"); size2=get_array(array2); printf("\nYou entered these numbers:\n"); disp_array(size2,array2); sort_array(size2,array2); printf("\nIn descending order, these are the number you entered:\n"); disp_array(size2,array2); merge(size1,array1,size2,array2,array3); printf("\nThese are the numbers you entered, merged and sorted:\n"); disp_array(size1+size2,array3); printf("\nEnter value to locate (CTRL-D to end): "); while (scanf("%lf",&value)!=EOF) { location=search(size1+size2,array3,value); if (location==-1) printf("Could not find %lf in the list.\n",value); else printf("Value: %lf was found at location: %i\n", array3[location],location+1); printf("Enter value to locate: "); } printf("\n"); return 0; }
int main(int argc, char **argv) { int n; if ( argc > 1 ) { if ( (fp = fopen(argv[1], "r")) == NULL ) { fprintf( stderr, "%s", Usage ); bu_exit(1, "pixhist3d: can't open \"%s\"\n", argv[1] ); } } else fp = stdin; if ( isatty(fileno(fp)) ) { bu_exit(2, "%s", Usage ); } if ( (fbp = fb_open( NULL, 512, 512 )) == NULL ) { bu_exit(12, "fb_open failed\n"); } while ( (n = fread(&ibuf[0], sizeof(*ibuf), sizeof(ibuf), fp)) > 0 ) { register unsigned char *bp; register int i; bp = &ibuf[0]; for ( i = n/3; i > 0; i--, bp += 3 ) { rxb[ bp[RED] ][ bp[BLU] ]++; rxg[ bp[RED] ][ bp[GRN] ]++; bxg[ bp[BLU] ][ bp[GRN] ]++; } } disp_array( rxg, 0, 0 ); disp_array( rxb, 256, 0 ); disp_array( bxg, 0, 256 ); fb_close( fbp ); return 0; }
int count_sort(int src[], int dst[], int len, int max_num) { int *c = calloc(max_num, sizeof(int)); int i; for(i = 0; i < len; i++) { c[src[i]]++; } for(i = 1; i < max_num; i++) { c[i] += c[i - 1]; } disp_array(c, max_num); for(i = len; i >= 0; i--) { dst[--c[src[i]]] = src[i]; } disp_array(c, max_num); free(c); return 0; }
int main(int argc, char **argv) { int n; if (argc > 1) { if ((fp = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "%s", Usage); bu_exit(1, "pixhist3d: can't open \"%s\"\n", argv[1]); } } else fp = stdin; if (isatty(fileno(fp))) { bu_exit(2, "%s", Usage); } if ((fbp = fb_open(NULL, 512, 512)) == NULL) { bu_exit(12, "fb_open failed\n"); } #define CHECK_INDEX(idx) \ if (idx > MAX_INDEX) { \ bu_exit(3, "pixhist3d: read invalid index %u\n", (unsigned int)idx); \ } while ((n = fread(&ibuf[0], sizeof(*ibuf), sizeof(ibuf), fp)) > 0) { unsigned char *bp; int i; long r, g, b; CHECK_INDEX(ibuf[RED]); CHECK_INDEX(ibuf[GRN]); CHECK_INDEX(ibuf[BLU]); bp = &ibuf[0]; for (i = n/3; i > 0; i--, bp += 3) { r = bp[RED]; g = bp[GRN]; b = bp[BLU]; /* sanitize no-op */ if (UNLIKELY(r < 0)) r = 0; if (UNLIKELY(r > 255)) r = 255; if (UNLIKELY(g < 0)) g = 0; if (UNLIKELY(g > 255)) g = 255; if (UNLIKELY(b < 0)) b = 0; if (UNLIKELY(b > 255)) b = 255; rxb[ r ][ b ]++; rxg[ r ][ g ]++; bxg[ b ][ g ]++; } } disp_array(rxg, 0, 0); disp_array(rxb, 256, 0); disp_array(bxg, 0, 256); fb_close(fbp); return 0; }