TEAM *input_dat(FILE *fp, int *num_team) { char line[SIZE_STR], **token; int i, num_token; int cmp_pts(); TEAM team_home, team_away, *team_ary; struct list *team_list, *p; *num_team = 0; team_list = init_list(); while (fgets(line, SIZE_STR, fp) != NULL) { if (line[0] != '#') { token = tokenize_str(line, "-\t\n", &num_token); if (num_token >= 4) { set_home_team(&team_home, token); set_away_team(&team_away, token); if ((p = search_team(team_list, team_home.name)) == NULL) { push_queue(team_list, &team_home, sizeof(team_home)); (*num_team)++; } else { add_team_result(p, team_home); } if ((p = search_team(team_list, team_away.name)) == NULL) { push_queue(team_list, &team_away, sizeof(team_away)); (*num_team)++; } else { add_team_result(p, team_away); } } free_token_ary(token, num_token); } } team_ary = (TEAM *) malloc(sizeof(TEAM) * (*num_team)); if (team_ary == NULL) { fprintf(stderr, "ERROR: Unable to allocate memory.\n"); exit(EXIT_FAILURE); } for (i = 0; i < *num_team; i++) { pop_queue(team_list, &team_ary[i], sizeof(TEAM)); } delete_list(team_list); /* 安定ソートで被ゴール数→ゴール数→得失点差→勝ち点の順で整列すると順位で並ぶ */ /* リーグ戦の規程によってはこのやり方ではダメ */ bubblesort(team_ary, *num_team, sizeof(TEAM), cmp_gag); bubblesort(team_ary, *num_team, sizeof(TEAM), cmp_gfo); bubblesort(team_ary, *num_team, sizeof(TEAM), cmp_gdi); bubblesort(team_ary, *num_team, sizeof(TEAM), cmp_pts); return team_ary; }
/** * Test that bubblesort() correctly sorts an array of two * strings. */ static void bubblesort_two_strings(void) { char *a[2]; /* The array is already sorted - no designation */ a[0] = test; a[1] = tset; bubblesort(a, 2); CU_ASSERT_EQUAL(a[0], test); CU_ASSERT_EQUAL(a[1], tset); /* The array is in revers order - no designation */ a[0] = tset; a[1] = test; bubblesort(a, 2); CU_ASSERT_EQUAL(a[0], test); CU_ASSERT_EQUAL(a[1], tset); /* The array is already sorted - with designations */ a[0] = test_1; a[1] = tset_1; bubblesort(a, 2); CU_ASSERT_EQUAL(a[0], test_1); CU_ASSERT_EQUAL(a[1], tset_1); /* The array is in reverse order - with designation */ a[0] = tset_1; a[1] = test_1; bubblesort(a, 2); CU_ASSERT_EQUAL(a[0], test_1); CU_ASSERT_EQUAL(a[1], tset_1); /* The array is already sorted - mixed designations */ a[0] = test_1; a[1] = tset; bubblesort(a, 2); CU_ASSERT_EQUAL(a[0], test_1); CU_ASSERT_EQUAL(a[1], tset); /* The array is in reverse order - mixed designations */ a[0] = tset; a[1] = test_1; bubblesort(a, 2); CU_ASSERT_EQUAL(a[0], test_1); CU_ASSERT_EQUAL(a[1], tset); /* The array is already sorted - differing designations */ a[0] = test_1; a[1] = test_99; bubblesort(a, 2); CU_ASSERT_EQUAL(a[0], test_1); CU_ASSERT_EQUAL(a[1], test_99); /* The array is in reverse order - differing designations */ a[0] = test_99; a[1] = test_1; bubblesort(a, 2); CU_ASSERT_EQUAL(a[0], test_1); CU_ASSERT_EQUAL(a[1], test_99); }
int main() { int number_array[20] = {1,2,200,10,34,65,23,78,79,11,23,55,123,1001,91,11221,1,7,203020,12}; int i,r; int size0 = 80; int size1 = 80; *((volatile unsigned int *)0xf000f008) = (unsigned int)(number_array); *((volatile unsigned int *)0xf000f00C) = 100; printf("------Original Array-------\n"); for(i=0; i<20; i++) { printf("%d \n", number_array[i]); } r = bubblesort(number_array, size0, number_array, size1); printf("------Sorted Array-------\n"); for(i=0; i<20; i++) { printf("%d \n", number_array[i]); } return 0; }
int main(void) { printf("Enter number of entries: "); scanf("%d", &testArrayTotal); for (int i = 0; i < testArrayTotal; i++) { printf("Enter a number: "); scanf("%d", &testArray[i]); } *testArray = *bubblesort(testArray, testArrayTotal); printf("\nThe sorted list is: "); for (int i = 0; i < testArrayTotal; i++) { printf("%i ", testArray[i]); } printf("\n\n"); return 0; }
/****************************************************************************************** * 起泡排序测试程序 ******************************************************************************************/ void main ( int argc, char* argv[] ) { int n = 0; //array length if ( 1 < argc ) n = atoi ( argv[1] ); if ( n < 0 ) n = 0; //make sure length is non-negative int* A = ( int* ) malloc ( n * sizeof ( int ) ); //allocate an array of size n unsigned int seed = ( unsigned int ) time ( NULL ); //A same seed is used here for comparison between different algorithms printf ( "\n== Bubblesort algorithm #0 ========\n" ); randomArray ( A, n, seed ); //create a randomized array using the same seed printf ( "--> " ); print ( A, n ); bubblesort ( A, n ); //sort the array using algorithm#0 printf ( "==> " ); print ( A, n ); printf ( "\n== Bubblesort algorithm #1A ========\n" ); randomArray ( A, n, seed ); //create a randomized array using the same seed printf ( "==> " ); print ( A, n ); bubblesort1A ( A, n ); //sort the array using algorithm#1A printf ( "==> " ); print ( A, n ); printf ( "\n== Bubblesort algorithm #1B ========\n" ); randomArray ( A, n, seed ); //create a randomized array using the same seed printf ( "==> " ); print ( A, n ); bubblesort1B ( A, n ); //sort the array using algorithm#1B printf ( "==> " ); print ( A, n ); printf ( "\n== Bubblesort algorithm #2 ========\n" ); randomArray ( A, n, seed ); //create a randomized array using the same seed printf ( "==> " ); print ( A, n ); bubblesort2 ( A, n ); //sort the array using algorithm#2 printf ( "==> " ); print ( A, n ); free ( A ); //release the array }
int main(){ int a[] = {9,8,7,6,5,4,3,2,1,0}; bubblesort(a, 10); int b; double c; return 0; }
int main( int argc, char *argv[]) { #ifndef FACTOR if ( argc == 1 ) { printf("The prime factors of 13195 are 5, 7, 13 and 29.\n"); printf("What is the largest prime factor of the number 600851475143 ?\n"); int primes[100]; int p = 0; prime_factor(600851475143L, &p, primes); int max = 0; for ( int i = 0; i < p; i++) if(primes[i] > max) max = primes[i]; printf("Answer: %d\n", max); } #endif #ifdef FACTOR if( argc == 2 ) { unsigned long factor = atol(argv[1]); int primes[100]; int p = 0; prime_factor(factor, &p, primes); printf("%lu:", factor); bubblesort(primes, p); for( int i = 0; i < p; i++) printf(" %d", primes[i]); printf("\n"); } #endif }
int main() { //Inicializa a biblioteca gráfica com a estrutura a ser apresentada na tela init($VETOR,MAX,1); setDataType(float); int i = 0; setSleepTime(1); for(i = 0; i < MAX; i++) { vetor[i] = rand()%100; } setSleepTime(2); show(&vetor,0); setSleepTime(1); bubblesort(); setSleepTime(10); show(&vetor,0); terminateDSGraph(); return 0; }
int main() { int * items, * sorted, i; items = (int *) malloc(ITEMS_LENGTH * sizeof(int)); for(i = 0; i < ITEMS_LENGTH; i++) scanf("%d", &items[i]); sorted = (int *) malloc(ITEMS_LENGTH * sizeof(int)); for(i = 0; i < ITEMS_LENGTH; i++) sorted[i] = items[i]; sorted = bubblesort(sorted); for(i = 0; i < ITEMS_LENGTH; i++) printf("%d\n", sorted[i]); printf("\n"); for(i = 0; i < ITEMS_LENGTH; i++) printf("%d\n", items[i]); return 0; }
int main(int argc, char const *argv[]) { int array[100], i; int numofelement; printf("Enter number of element in array:\n"); scanf("%d",&numofelement); printf("Enter element of array:\n"); for (i = 0; i < numofelement; i++) { scanf("%d",&array[i]); } printf("elements of array: before sorting\n"); for (i = 0; i < numofelement; i++) { printf("%d\n",array[i]); } printf("elements of array: after sorting\n"); bubblesort(array, numofelement); for (i = 0; i < numofelement; i++) { printf("%d\n",array[i]); } return 0; }
void scan_root(void){ if (artist_list != NULL) {rprintf("already scanned.\n");return;} char long_pathname[40] = "0:/MUSIC"; rprintf("scanning 0:/MUSIC\n"); scan_files(long_pathname); rprintf("found artists: "); num_of_artists = 0; unsigned int num_of_tracks = 0; Artist * list_cpy = artist_list; while(list_cpy != NULL) { num_of_artists++; list_cpy->tracks = bubblesort(list_cpy->tracks); unsigned int arts_trks = 0; for (Track *tmp=list_cpy->tracks; tmp->next != NULL; tmp=tmp->next) { arts_trks++; } //counts how many tracks this artist has rprintf("%s [%i], ",list_cpy->name, arts_trks ); num_of_tracks += arts_trks; //add artist total to the overall total. list_cpy = list_cpy->next; } rprintf("\nnumber of: artists=%i, tracks=%i \n",num_of_artists,num_of_tracks); }
int main(void){ int i; printf("N? "); scanf("%d", &N); /*set random numbers Bubble[], Quick[], Merge[]*/ srand((unsigned int)time(0)); for(i = 0; i < N; i++){ Bubble[i] = Quick[i] = Merge[i] = (rand() % 10000) + 1; } time(&tm1); /*tm1(秒)*/ bubblesort(); time(&tm2); /*tm2(秒)*/ printf("Bubble Sort %ld sec \n", tm2 - tm1); time(&tm1); /*tm1(秒)*/ quicksort(0, N - 1); time(&tm2); /*tm2(秒)*/ printf("Quick Sort %ld sec \n", tm2 - tm1); time(&tm1); /*tm1(秒)*/ m_sort(0, N - 1); time(&tm2); /*tm2(秒)*/ printf("Merge Sort %ld sec \n", tm2 - tm1); return 0; }
int main(int argc, char **argv) { srand(time(NULL)); int numbers[SIZE]; int i; for (i = 0; i < SIZE; ++i) { numbers[i] = rand() % (SIZE + 1); } for (i = 0; i < SIZE; ++i) { printf("%d: %d\n", i, numbers[i]); } bubblesort (numbers, SIZE); assert( sorted(numbers, SIZE)); return(0); }
// sort thread shall behave the same as hw thread: // - get pointer to data buffer // - if valid address: sort data and post answer // - if exit command: issue thread exit os call void *sort_thread(void* data) { unsigned int ret; unsigned int dummy = 23; struct reconos_resource *res = (struct reconos_resource*) data; struct mbox *mb_start = res[0].ptr; struct mbox *mb_stop = res[1].ptr; //pthread_t self = pthread_self(); //printf("SW Thread %lu: Started with mailbox addresses %p and %p ...\n", self, mb_start, mb_stop); while ( 1 ) { ret = mbox_get(mb_start); //printf("SW Thread %lu: Got address %p from mailbox %p.\n", self, (void*)ret, mb_start); if (ret == UINT_MAX) { // printf("SW Thread %lu: Got exit command from mailbox %p.\n", self, mb_start); pthread_exit((void*)0); } else { bubblesort( (unsigned int*) ret, N); } mbox_put(mb_stop, dummy); } return (void*)0; }
int main(void){ int i; double t, x, y, z; /*t: ソート処理前のclock, x: バブルソート実行時間, *y: クイックソート実行時間, z: マージソート実行時間 */ printf("N? "); scanf("%d", &N); /*set random numbers Bubble[], Quick[], Merge[]*/ srand((unsigned int)time(0)); for(i = 0; i < N; i++){ Bubble[i] = Quick[i] = Merge[i] = (rand() % 10000) + 1; } t = clock(); bubblesort(); x = (clock() - t) / CLOCKS_PER_SEC; printf("Bubble Sort %g sec \n", x); t = clock(); quicksort(0, N - 1); y = (clock() - t) / CLOCKS_PER_SEC; printf("Quick Sort %g sec \n", y); t = clock(); m_sort(0, N - 1); z = (clock() - t) / CLOCKS_PER_SEC; printf("Merge Sort %g sec \n", z); return 0; }
void MoveList::sort(int start, int end) { if (end < 0) end = size - 1; bubblesort(start, end); }
int main() { int a[7]={9,4,5,6,7,2,3}; insertsort(a,7); bubblesort(a,7); selectsort(a,7); }
int main(void){ int i; printf("N?"); scanf("%d", &N); /*1~10000の乱数を発生させ、Bubble[], Quick[]に格納*/ srand((unsigned int)time(0)); for(i = 0; i < N; i++){ Bubble[i] = Quick[i] = rand() % 10000 + 1; } printf("Input: "); for(i = 0; i < N; i++){ printf("%d ", Bubble[i]); if(i % 10 == 9){ printf("\n"); } } printf("\n"); /*****BubbleSort*****/ printf("Bubble Sort start\n"); bubblesort(); /*Bubble[0]~Bubble[N-1]をソート*/ printf("Bubble Sort end: "); printdata(Bubble); /*バブルソートの結果出力*/ /*****QuickSort*****/ printf("Quick Sort start\n"); quicksort(0, N-1); /*Quick[0]~Quick[N-1]をソート*/ printf("Quick Sort end: "); printdata(Quick); /*クイックソートの結果出力*/ return 0; }
int main(void){ int n, i ,vetor1[MAX],vetor2[MAX]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&vetor1[i]); } for(i=0;i<n;i++) { vetor2[i]=vetor1[i]; } bubblesort(vetor1,n); printf("Bubble Sort iterativo:\n"); for(i=0;i<n;i++) { printf("%d ",vetor1[i]); } printf("\n"); bubblesortR(vetor2,0,n); printf("Bubble Sort recursivo:\n"); for(i=0;i<n;i++) { printf("%d ",vetor2[i]); } printf("\n"); return 0; }
int main(int argc, char* argv[]) { std::vector<int> v; v.push_back(4); v.push_back(5); v.push_back(0); v.push_back(2); v.push_back(1); v.push_back(3); for (std::vector<int>::iterator it = v.begin(); it != v.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; bubblesort(v.begin(), v.end()); for (std::vector<int>::iterator it = v.begin(); it != v.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; // jetzt fuer listen std::list<int> l; l.push_back(4); l.push_back(5); l.push_back(0); l.push_back(2); l.push_back(1); l.push_back(3); for (std::list<int>::iterator it = l.begin(); it != l.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; bubblesort(l.begin(), l.end()); for (std::list<int>::iterator it = l.begin(); it != l.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; }
int main() { int a[length] = {4,2,7,1,5}; bubblesort(a,length); for(int i=0;i<length;++i) printf("%d ",a[i]); return 0; }
int main() { int n = __VERIFIER_nondet_int(); if (n < 1) { n = 1; } int *a = malloc(n * sizeof(int)); bubblesort(a,n-1); }
/** * Test that calling bubblesort() with an array containing * one string, or NULL, works. */ static void bubblesort_one_string(void) { char *a[1]; a[0] = test; bubblesort(a, 1); bubblesort(NULL, 0); CU_ASSERT_EQUAL(a[0], test); a[0] = test_1; bubblesort(a, 1); CU_ASSERT_EQUAL(a[0], test_1); a[0] = NULL; bubblesort(a, 1); CU_ASSERT_PTR_NULL(a[0]); }
void check_top_ten(void) { if (players[10].points> players[9].points) {bubblesort();} save_score(); highscore(); }
int main() { int a[] = {49, 38, 65, 97, 76, 13, 27}; bubblesort(a, 7); for (int i = 0; i < 7; i++) { printf("%d ", a[i]); } return 0; }
int main() { int n = __VERIFIER_nondet_int(); if (n < 1) { n = 1; } int a[n]; bubblesort(a,n-1); }
void main() { int a[10]={11,22,553,20,65,81,19}; int size=7; bubblesort(a,size); for(int i=0; i<size; i++) cout << a[i] << " "; getch(); }
void * bubblesort_thread (void * arg) { targ_t * targ = (targ_t*)arg; // Sort the data bubblesort(targ->data, targ->length); return (void*)(999); }
main() { void bubblesort(int[],int); int a[5]; printf("enter the numbers"); for(i=0; i<5; i++) scanf("%d",&a[i]); bubblesort(a,5); }
int swap(int x,int y) { int temp; temp=x; x=y; y=temp; printf("x=%d,y=%d",x,y); bubblesort(); }