int main(void) { wood array[5000]; int T; int n; int time1, time2; int mininum; int i; scanf("%d", &T); while(T--) { scanf("%d", &n); time1 = 1; time2 = 1; for(i = 0; i < n; i++) scanf("%d %d", &array[i].l, &array[i].w); insert_sort(array, n, 1); time1 += gettime(array, n, 1); insert_sort(array, n, 0); time2 += gettime(array, n ,0); if(time2 >= time1) mininum = time1; else mininum = time2; printf("%d\n", mininum); } exit(EXIT_SUCCESS); }
int main(void) { /* int a[] = {1, 8, 2, 7, 3, 5} ; int b[] = {1, 8, 2, 7, 3, 5} ; int i; insert_sort(a, 6, 1); insert_sort(b, 6, 0); for(i = 0; i < 6; i++) printf("%d ", a[i]); printf("\n"); for(i = 0; i < 6; i++) printf("%d ", b[i]); printf("\n");*/ int a[10+5] = {0}; int n = 10; while(1) { int i; int cur_num; int odd_count = 0; int even_start = 9; memset(a, 0, sizeof(a)/sizeof(int)); if(scanf("%d", &cur_num) == EOF) break; if(cur_num % 2 != 0) a[odd_count++] = cur_num; else a[even_start--] = cur_num; for(i = 0; i < 9; i++) { scanf("%d", &cur_num); if(cur_num % 2 != 0) a[odd_count++] = cur_num; else a[even_start--] = cur_num; } /* for(i = 0; i < 10; i++) printf("%d ", a[i]); printf("\n");*/ insert_sort(&a[0], odd_count, 0); insert_sort(&a[odd_count], 10-odd_count,1 ); printf("%d", a[0]); for(i = 1; i < 10; i++) printf(" %d", a[i]); printf("\n"); } return 0; }
int main() { int *p=(int *)calloc(sizeof(int),100000); int i=1; while(scanf("%d",&p[i]) != EOF ) i++; int length=i-1; insert_sort(p,length,200); insert_sort(p,length,20); insert_sort(p,length,7); insert_sort(p,length,1); show_sort(p,length); }
void test_sorting(int *numbers, int count, compare_cb cmp) { int i = 0; int *sorted = bubble_sort(numbers, count, cmp); if (!sorted) die("Failed to sort as requested."); for(i = 0; i < count; i++) { printf("%d ", sorted[i]); } printf("\n"); free(sorted); sorted = insert_sort(numbers, count, cmp); if (!sorted) die("Failed to sort as requested."); for(i = 0; i < count; i++) { printf("%d ", sorted[i]); } printf("\n"); free(sorted); unsigned char *data = (unsigned char *)cmp; for (i = 0; i < 25; i++) { printf("%02x:", data[i]); } printf("\n"); }
int main(int argc, char* argv[]) { int arr[15] ; arr_init(arr, 15); arr_show("before", arr, 15); buble_sort(arr, 15); arr_show("buble", arr, 15); arr_init(arr, 15); arr_show("before", arr, 15); select_sort(arr, 15); arr_show("select", arr, 15); arr_init(arr, 15); arr_show("before", arr, 15); insert_sort(arr, 15); arr_show("insert", arr, 15); arr_init(arr, 15); arr_show("before", arr, 15); quick_sort(arr, 15); arr_show("quick", arr, 15); arr_init(arr, 15); arr_show("before", arr, 15); heap_sort(arr, 15); arr_show("heap", arr, 15); return 0 ; }
int main(void) { rice *Rice; int Case; int n, m, i; float max; scanf("%d", &Case); while(Case--) { scanf("%d %d\n", &n, &m); max = 0.0; Rice = malloc(sizeof(rice) * m); for(i = 0; i < m; i++) scanf("%d %d", &Rice[i].price, &Rice[i].heigh); insert_sort(Rice, m); for(i = 0; i < m; i++) { if(Rice[i].price * Rice[i].heigh >= n) { max += (float)n / Rice[i].price; break; } else { max += Rice[i].heigh; n -= Rice[i].price * Rice[i].heigh; } } printf("%.2f\n", max); } exit(EXIT_SUCCESS); }
int main() { int arr[]={5,2,3,1,4,6}; insert_sort(arr,6); printIntArr(arr,6); return 0; }
int insert_alg_main() { unsigned int MAX_TEST_NUMBER=100000; printf("print option:"); std::string str; while(std::cin>>str) { printf("printf test number\n"); scanf("%u",&MAX_TEST_NUMBER); int* array =new int[MAX_TEST_NUMBER]; clock_t start=clock(); makedata(array,MAX_TEST_NUMBER); insert_sort(array,MAX_TEST_NUMBER); std::cout<<"sort "<<MAX_TEST_NUMBER<<" use "<<(double)(clock()-start)/CLOCKS_PER_SEC<<" ms "<<std::endl; printf("print option:"); FILE* fp=fopen("inser_sort.result","w"); for(int i=0;i!=MAX_TEST_NUMBER;i++) { fprintf(fp,"%d\t",array[i]); if(i%10==0) fprintf(fp,"\n"); } fclose(fp); delete[] array; } return 0; }
ListNode* insertionSortList(ListNode* head) { if (head == NULL) return head; ListNode *remain = head->next; head->next = NULL; return insert_sort(head, remain); }
double sortTime(char *compareType,double a[],int length) { // struct timeval tv0; // struct timezone tz0; // gettimeofday (&tv0, &tz0); clock_t start, finish; double elapsed_time; start=clock(); if (strcmp(compareType,"insert_sort") == 0) { insert_sort(a,length); } else if (strcmp(compareType,"select_sort") == 0) { select_sort(a,length); } finish=clock(); elapsed_time = finish-start; // struct timeval tv; // struct timezone tz; // gettimeofday (&tv, &tz); // return tv.tv_usec - tv0.tv_usec; return elapsed_time; }
int main() { int a[10] = {23, 1, 34, 21, 11, 4, 5, 2, 1, 12}; for(int i = 0; i < 10; i++) { printf("a[%d]: %d \n", i, a[i]); } insert_sort(a, 10); for(int i = 0; i < 10; i++) { printf("a[%d]: %d \n", i, a[i]); } int b[]= {11 ,3 ,1 ,5 ,2 ,23 ,8 ,4 ,1 ,123}; for(int i = 0; i < 10; i++) { printf("b[%d]: %d \n", i, b[i]); } insert_sort2(b, 10); for(int i = 0; i < 10; i++) { printf("b[%d]: %d \n", i, b[i]); } return 0; }
int main() { std::vector<int> v = {1, 5, 4, 3, 2, 10, 7, 6, 8, 9}; insert_sort(v); print_v_int(v); return 0; }
void get_da_list(t_dlist **files, t_params *params, char *dir2open) { DIR *dir; t_dirent *dirent; if ((dir = opendir(dir2open)) == NULL) { error(BAD_PATH_NO_EXIT, dir2open); return ; } while ((dirent = readdir(dir)) != NULL) { if (params->param_a == 0 && params->all == 0 && ft_strncmp(dirent->d_name, ".", 1) == 0) ; else { if (params->param_a == 1 && is_parent_or_cur(dirent->d_name) == 1 && params->all == 0) ; else insert_sort(dirent->d_name, files, dir2open); } } if (closedir(dir) == -1) error(-1, NULL); }
t_dlist *get_all_files(t_mega *all) { struct stat sb; t_dirent *dirent; t_dlist *files; DIR *dir; int len; files = NULL; all->p.path = NULL; len = ft_strlen(all->p.file); if (stat(all->p.file, &sb) != -1 && S_ISDIR(sb.st_mode)) { all->p.path = all->p.file[len] == '/' ? ft_strdup(all->p.file) : ft_strjoin(all->p.file, "/"); if ((dir = opendir(all->p.file)) == NULL) error(NO_SUCH_FILE, all); while ((dirent = readdir(dir)) != NULL) if (ft_strncmp(dirent->d_name, ".", 1) != 0) insert_sort(dirent->d_name, &files, all); if (closedir(dir) == -1) error(SYSCALL_FAIL, NULL); return (files); } return (NULL); }
int main(int argc, char* argv[]){ if(argv[1]==NULL || argv[2]==NULL){ printf("ERROR : Insert the arguments\ne.g)sorting_exe Q sample.txt\n"); return 0; } fi = fopen(argv[2],"r"); int arr[1000000]; int* tarr; int num; int i=0; char sort_type; struct timespec start,end; sort_type = *argv[1]; while(!feof(fi)){ fscanf(fi,"%d ",&num); arr[i++]=num; } int length = i; int tlength; switch(sort_type){ case 'Q': clock_gettime(CLOCK_REALTIME,&start); quick_sort(arr,0,length-1); clock_gettime(CLOCK_REALTIME,&end); break; case 'M': tarr=(int*)malloc(sizeof(int)*length); for(i=0;i<length;i++){ tarr[i]=arr[i]; } clock_gettime(CLOCK_REALTIME,&start); merge_sort(arr,tarr,0,length-1); clock_gettime(CLOCK_REALTIME,&end); break; case 'C': tlength = maximum(arr,length)+1; tarr = (int*)malloc(sizeof(int)*tlength); clock_gettime(CLOCK_REALTIME,&start); counting_sort(arr,tarr,length,tlength); clock_gettime(CLOCK_REALTIME,&end); break; case 'I': clock_gettime(CLOCK_REALTIME,&start); insert_sort(arr,length); clock_gettime(CLOCK_REALTIME,&end); break; default: printf("ERROR : Input appropriate arguments\nyou should input Q,M,I and C\n"); return 0; break; } print_arr(arr,length); printf("\n"); convert2second(&start,&end); return 0; }
int main(void) { int iii = 0; int data_number = 0; int* source_data = 0; source_data = get_input_data(&data_number); printf("before sort:\n"); for (iii = 0; iii < data_number; iii++) { printf("%d,", source_data[iii]); } printf("\n"); insert_sort(source_data, data_number); printf("after sort:\n"); for (iii = 0; iii < data_number; iii++) { printf("%d,", source_data[iii]); } printf("\n"); if(source_data) free(source_data); return 0; }
int main() { int a[] = {2, 5, 3, 1, 4}; show(a, 5); insert_sort(a, 5); show(a, 5); return 0; }
int main(void) { int a[N] = {49,38,65,78,13,27}; show(a); insert_sort(a); return 0; }
int main(int argc, char *argv[]) { int array[] = { 12, 57, 90, 8, 34, 67, 76, 24 }; insert_sort(array, 8); for (int i = 0; i < 8; i++) { printf("%d ", array[i]); } }
int main(void) { int a[] = { 63, 35, 56, 155, -1, -1456, 576 }; const int len = sizeof(a) / sizeof(a[0]); dump(a, len, "before insert sort, array:"); insert_sort(a, len); dump(a, len, "after insert sort, array:"); return 0; }
int main(){ int i; int a[] = {2, 5, 6, 3, 7, 8, 0, 9, 12, 1}; insert_sort(a, LENGTH); for(i = 0; i < LENGTH; ++i){ printf("%d", a[i]); printf(","); } }
int main() { int nums[7] = {1, 6, 8, 2, 10, 4, 9}; print(nums, 7); insert_sort(nums, 7); print(nums, 7); return 0; }
int main(){ int i; int data[]={1,2,7,6,5,3,4}; insert_sort(data,7); for(i=0;i<7;i++) { printf("%d\n",data[i]); } }
int main(){ int * array = NULL; array = create_array(); random_array(array); print_array(array); insert_sort(array); print_array(array); free_array(array); return 0; }
int main(int argc, const char *argv[]) { int a[] ={50,36,66,76,95,12,25,36}; show(a); insert_sort(a); show(a); return 0; }
int main(void) { int a[N]; init_array(a, N); show_array(a, N); insert_sort(a, N); show_array(a, N); return 0; }
int main(int argc, char *argv[]){ scanf("%d",&argc); int arr[argc]; for(int i=0;i<argc;i++) scanf("%d",&arr[i]); insert_sort(arr,argc); print_arr(arr,argc); return 0; }
int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "usage: %s <sort algorithm> <array size>\n", argv[0]); exit(-1); } int count = atoi(argv[2]); int *array = (int*)malloc(sizeof(int) * count); if (array == NULL) { perror("malloc error"); exit(-1); } int i; srand(time(NULL)); printf("sorting"); for (i = 0; i < count; ++i) { array[i] = rand() & 0xff; printf(" %d", array[i]); } printf("\n"); if (strcmp(argv[1], "bubble") == 0) { bubble_sort(array, count); } else if (strcmp(argv[1], "merge") == 0) { merge_sort(array, 0, count, NULL); } else if (strcmp(argv[1], "insert") == 0) { insert_sort(array, count); } else if (strcmp(argv[1], "heap") == 0) { heap_sort(array, count); } else if (strcmp(argv[1], "quick") == 0) { quick_sort(array, 0, count); } else { fprintf(stderr, "unknown sort algorithm\n"); exit(-1); } printf("result is"); for (i = 0; i < count - 1; ++i) { printf(" %d", array[i]); if (array[i] > array[i+1]) { printf("sort error\n"); for (i = 0; i < count; ++i) { printf("%d ", array[i]); } exit(-1); } } if (count > 0) { printf(" %d", array[i]); } printf("\nsort OK\n"); return 0; }
int main(int argc, const char * argv[]){ int a[] = {4, 1, 5, 9, 2, 1, 3, 7}; int len = sizeof(a)/sizeof(a[0]); insert_sort(a, len); for(int index=0; index<len; index++){ cout<<a[index]<<'\t'; } return 0; }
void main() { int opt; clrscr(); do { clrscr(); printf("\npress 1 for insert beg:"); printf("\npress 2 for insert end:"); printf("\npress 3 for insert after:"); printf("\npress 4 for insert before:"); printf("\npress 5 for delete beg:"); printf("\npress 6 for delete end:"); printf("\nlpress 7 for delete after :"); printf("\npress 8 for delete before:"); printf("\npress 9 for deleter that:"); printf("\npress 10 for delete odd:"); printf("\npress 11 for delete even:"); printf("\npress 12 for sorting:"); printf("\npress 13 for reverse:"); printf("\npress 14 for insert in sorted order ;"); printf("\npress 15 for display"); printf("\nenter the option:"); scanf("%d",&opt); switch(opt) { case 1:insert_beg(&ptr); break; case 2:insert_end(&ptr);break; case 3:insert_after(&ptr);break; case 4:insert_before(&ptr);break; case 5:delete_beg(&ptr); break; case 6:delete_end(&ptr);break; case 7:delete_after(&ptr);break; case 8:delete_before(&ptr);break; /**/ case 9:delete_that(&ptr);break; case 10:delete_alter_odd(&ptr);break; case 11:delete_alter_even(&ptr);break; case 12:sort(&ptr);break; case 13:reverse(&ptr);break; /**/ case 14:insert_sort(&ptr);break; case 15:display(&ptr);break; } getch(); }while(opt!=99); getch(); }