static void SortedIntersection()//PROBLEM 16 { int boolean = 1; int content; struct node *Ahead = NULL; struct node *Bhead = NULL; struct node *Chead = NULL; while(boolean) { if(yesno("Would you like to enter a value for Ahead (Y/N)?")) { read_int("Please enter your value: ", &content); Push(&Ahead, content); } else { boolean = 0; } Insert_Sort(&Ahead); } boolean = 1; while(boolean) { if(yesno("Would you like to enter a value for Bhead (Y/N)?")) { read_int("Please enter your value: ", &content); Push(&Bhead, content); } else { boolean = 0; } Insert_Sort(&Bhead); } PrintListData(Ahead); PrintListData(Bhead); PrintListData(Chead); Sorted_Intersection(&Ahead, &Bhead, &Chead); PrintListData(Ahead); PrintListData(Bhead); PrintListData(Chead); freeElements(&Ahead);//free up the allocated memory if(Ahead == NULL) { printf("The head node was set to NULL.\n"); } freeElements(&Bhead);//free up the allocated memory if(Bhead == NULL) { printf("The head node was set to NULL.\n"); } freeElements(&Chead);//free up the allocated memory if(Chead == NULL) { printf("The head node was set to NULL.\n"); } }//END PROBLEM 16
static void RemoveDuplicates()//PROBLEM 10 { int boolean = 1; int content; struct node *head = NULL; while(boolean) { if(yesno("Would you like to enter a value (Y/N)?")) { read_int("Please enter your value: ", &content); Push(&head, content); } else { boolean = 0; } } PrintListData(head); Insert_Sort(&head); PrintListData(head); Remove_Duplicates(&head); PrintListData(head); freeElements(&head);//free up the allocated memory if(head == NULL) { printf("The head node was set to NULL.\n"); } }//END PROBLEM 10
void insert() { extern int *input; int *copy_input[LOOP_COUNT]; int i, j; // Time check variable double time; BOOL err; for (i = 0; i < LOOP_COUNT; i++){ copy_input[i] = (int *) malloc(sizeof(int) * DATA_SIZE); for (j = 0; j < DATA_SIZE; j++) { // copy data copy_input[i][j] = input[j]; } } CHECK_TIME_START; for (i = 0; i < LOOP_COUNT; i++) { Insert_Sort(copy_input[i]); // if(x%(LOOP_COUNT/10) == 0) printf("*"); // printf("Selecting Result --> input[%d] : %d\n", result, input[result]); } CHECK_TIME_END(time, err); // // data output check // for (i = 0; i < DATA_SIZE; i++) { // if(i%(DATA_SIZE/10) == 0) printf("%d : %d, ", i, copy_input[i]); // } // printf(" Calc Time = %.0fus\n", time/LOOP_COUNT); printf("%.0f\n", time / LOOP_COUNT); }
void Insert_or_Merge(int A[],int B[],int N) { int i; int j; int flag = 0;/*flag=0是插入排序,flag=1是归并排序*/ for(i=1;i<N;i++){ if(B[i] < B[i-1]){ j = i; break; } } for(;i<N;i++){ if(A[i] != B[i]) flag = 1; } if(flag == 0){ printf("Insertion Sort\n"); Insert_Sort(B,j); } else{ printf("Merge Sort\n"); Merge_Sort(B,N); } printf("%d",B[0]); for(i=1;i<N;i++) printf(" %d",B[i]); }
int main(int argc, char *argv[]) { int a[ARR_NUM]={37,41,19,81,41,25,56,61,49},i; printf("Insert Sort 排序前 ( before sorting )\n"); for(i=0;i < ARR_NUM;i++) printf(" %d",a[i]); Insert_Sort(a,ARR_NUM); printf("\nInsert Sort 排序後 ( after sorting )\n"); for(i=0;i < ARR_NUM;i++) printf(" %d",a[i]); printf("\n"); system("PAUSE"); return EXIT_SUCCESS; }
int main(void) { int a[ARR_NUM] = {37, 41, 19, 81, 41, 25, 56, 61, 49}, i; printf("排序前 ( before sorting )\n"); for (i = 0; i < ARR_NUM; i++) { printf(" %d", a[i]); } Insert_Sort(a, ARR_NUM); printf("\n排序後 ( after sorting )\n"); for (i = 0; i < ARR_NUM; i++) { printf(" %d", a[i]); } printf("\n"); return 0; }