Exemplo n.º 1
0
int main() {
  std::vector<int> V = {1, 1, 0, 3, 4, 5, 1, 0, 5, 5, 3, 1, 2, 2, 2, 2};
  
  bubble_sort(V);
  
  printv(V);
  
  return 0;
}
Exemplo n.º 2
0
void test_to_sort_the_elements_list_of_double_datatype_when_list_is_already_sorted(){
        double before_sorting[3] = {4.0,7.0,8.0};
        double after_sorting[3] = {4.0,7.0,8.0,};
        void* elements[3] = {&before_sorting[0],&before_sorting[1],&before_sorting[2]};
        bubble_sort(elements,3,compare_doubles);
        ASSERT(after_sorting[0] == *(double*)elements[0]);
        ASSERT(after_sorting[1] == *(double*)elements[1]);
        ASSERT(after_sorting[2] == *(double*)elements[2]);

};
Exemplo n.º 3
0
void test_to_sort_the_elements_list_of_float_datatype_when_element_are_duplicate(){
        float before_sorting[3] = {7.0f,7.0f,4.0f};
        float after_sorting[3] = {4.0f,7.0f,7.0f};
        void* elements[3] = {&before_sorting[0],&before_sorting[1],&before_sorting[2]};
        bubble_sort(elements,3,compare_floats);
        ASSERT(after_sorting[0] == *(float*)elements[0]);
        ASSERT(after_sorting[1] == *(float*)elements[1]);
        ASSERT(after_sorting[2] == *(float*)elements[2]);

};
Exemplo n.º 4
0
void test_to_sort_the_elements_list_of_int_datatype_when_element_are_duplicate(){
        int before_sorting[3] = {4,2,2};
        int after_sorting[3] = {2,2,4};
        void* elements[3] = {&before_sorting[0],&before_sorting[1],&before_sorting[2]};
        bubble_sort(elements,3,compare_ints);
        ASSERT(after_sorting[0] == *(int*)elements[0]);
        ASSERT(after_sorting[1] == *(int*)elements[1]);
        ASSERT(after_sorting[2] == *(int*)elements[2]);

};
Exemplo n.º 5
0
void test_to_sort_the_elements_list_of_int_datatype_when_list_is_already_sorted(){
        int before_sorting[3] = {1,2,3};
        int after_sorting[3] = {1,2,3};
        void* elements[3] = {&before_sorting[0],&before_sorting[1],&before_sorting[2]};
        bubble_sort(elements,4,compare_ints);
        ASSERT(after_sorting[0] == *(int*)elements[0]);
        ASSERT(after_sorting[1] == *(int*)elements[1]);
        ASSERT(after_sorting[2] == *(int*)elements[2]);

};
Exemplo n.º 6
0
void test_to_sort_the_elements_list_of_string_datatype_when_element_are_duplicate(){
        String before_sorting[3] = {"dddd","bbcc","bbcc"};
        String after_sorting[3] = {"bbcc","bbcc","dddd"};
        void* elements[3] = {&before_sorting[0],&before_sorting[1],&before_sorting[2]};
        bubble_sort(elements,3,compare_chars);
        ASSERT(0==strcmp(after_sorting[0],*(String*)elements[0]));
        ASSERT(0==strcmp(after_sorting[1],*(String*)elements[1]));
        ASSERT(0==strcmp(after_sorting[2],*(String*)elements[2]));

};
Exemplo n.º 7
0
void test_to_sort_the_elements_list_of_char_datatype_when_element_are_duplicate(){
        char before_sorting[3] = {'d','c','c'};
        char after_sorting[3] = {'c','c','d'};
        void* elements[3] = {&before_sorting[0],&before_sorting[1],&before_sorting[2]};
        bubble_sort(elements,3,compare_chars);
        ASSERT(after_sorting[0] == *(char*)elements[0]);
        ASSERT(after_sorting[1] == *(char*)elements[1]);
        ASSERT(after_sorting[2] == *(char*)elements[2]);

};
int main(void)
{
    mylib::date dates[] = {mylib::date(1912,6,23), mylib::date(1941,9,9),
                           mylib::date(1943,2,4), mylib::date(1931,10,12),
                           mylib::date(1926,8,27)};
    size_t ndates = sizeof dates / sizeof dates[0];
    bubble_sort(dates, ndates);
    std::ostream_iterator<mylib::date> out_it(std::cout,"\n");
    std::copy(dates, dates + ndates, out_it);
}
Exemplo n.º 9
0
int main(int argc,char* argv[])
{
	const int len=10;
	int ary[10]={0,4,6,2,3,1,5,7,9,8};
	print(ary,len);
	bubble_sort(ary,len);
	print(ary,len);

	return 0;
}
Exemplo n.º 10
0
int main(int argc, const char *argv[])
{
    int i;
    int d[N]= {48,38,65,97,76,13,27,49};
    bubble_sort(d, N);
    for (i = 0; i < N; i++) {
        printf("%d \n",d[i]);
    }
    return 0;
}
int main(){
	int arr[]={-8,-3,-4,-6,-77,-88,-101};
	int arr_size=6;

	bubble_sort( arr, arr_size );
	print_array( arr, arr_size );

return 0;

}
Exemplo n.º 12
0
Arquivo: ex18.c Projeto: saisai/c-2
void test_sort(int *numbers, int count, compare_cb cmp) {
  int i = 0;
  int *sorted = bubble_sort(numbers, count, cmp);
  if (!sorted) die("Sorting fail.");
  for (i = 0; i < count; i++) {
    printf("%d ", sorted[i]);
  }
  printf("\n");
  free(sorted);
}
Exemplo n.º 13
0
int main()
{
    int N[10] = {1, 5, 4, 3, 2, 10, 7, 6, 8, 9};

    rand_array(N);
    print_array(N, 0);
    
    bubble_sort(N, 10);
    print_array(N, 0);
}
Exemplo n.º 14
0
int main(int argc,char** argv)
{
    int array[9] = {9,7,5,4,6,8,1,3,2};
    bubble_sort(array,9);
    int i;
    for(i=0;i<9;i++){
        printf("current:%d \n",array[i]);
    }
    return 0;
}
Exemplo n.º 15
0
int main(int argc, const char * argv[]) 
{    
    std::vector<int> array = create_random_array();
    std::cout << "  Before sorting: " << std::endl;
    printArray(array);
    bubble_sort(array);
    std::cout << "  After sorting: " << std::endl;
    printArray(array);
    return 0;
}
Exemplo n.º 16
0
int main(int argc, char argv[])
{
    int arr[] = {3, 5, 2, 7, 0};
    int len = sizeof(arr)/sizeof(int);

    bubble_sort(arr, len);
    print_res(arr, len);

    return 0;
}
Exemplo n.º 17
0
int main() {
    int arr[] = { 22, 34, 3, 32, 82, 55, 89, 50, 37, 5, 64, 35, 9, 70  };
    int len = (int) sizeof(arr) / sizeof(*arr);
    bubble_sort(arr, len);
    int i;
    for (i = 0; i < len; i++){
        printf("%d ", arr[i]);
}
    return 0;
}
int  main()
{
    int num[N] = {89, 38, 11, 78, 96, 44, 19, 25};
    bubble_sort(num, N); //或者使用bubble_sort_better(num, N);
    for(int i=0; i<N; i++)
        printf("%d  ", num[i]);
    printf("\n");
    system("pause");
    return 0;
}
int main()
{
   // 1. get valid filename and open that file
   char fname[500];
   FILE* f;
   do {
      printf("Enter filename with absolute path --> ");
      gets_s(fname, sizeof(fname));

      f = fopen(fname, "r");

      if (f == NULL)
         printf("Error! I could not open the specified file %s\n", fname);

   } while (f == NULL);

   // 2. read in all the numbers
   char line[500];
   int counter = 0;
   double A[1000];
   while (fgets(line, sizeof(line), f))
   {
      char* errptr1;
      double d = strtod(line, &errptr1);
      printf("Number #%d: %.5f\n", counter, d);

      // if the only thing from line that cannot be converted to a double
      // by strtod() is the newline character \n and the null termination
      // character \0, then everything was ok!
      if (strcmp(errptr1, "\n") == 0)      
      {
         A[counter] = d;
      }
      else
      {
         printf("Error: some characters of the string could not be converted!\n");
         _getch();
      }         
      counter++;
   }

   // 3. sort the array using Bubble sort https://en.wikipedia.org/wiki/Bubble_sort
   bubble_sort(A,counter);

   // 4. write sorted array to another file
   char fname2[1000];
   sprintf(fname2, "%s.sorted.txt", fname);
   FILE* f2=fopen(fname2, "w");
   for (int i=0; i<counter; i++)
      fprintf(f2, "%.5f\n", A[i]);
   fclose(f2);

   printf("Press any key to exit this program.");
   _getch();
}
Exemplo n.º 20
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 a[] = {5,3,4,2,1};
    int n = 5;
    int i = 0;
    bubble_sort(a,n);

    for(i=0; i<n; ++i)
        printf("%4d\n",a[i]);
    return 0;
}
 int main ()
 {
   first = malloc (sizeof(el_listy));
   first->val = 4;
   first->next = NULL;
   dodaj_do_listy(first,3);
   bubble_sort(2);
   wypisz_liste(first);
   //free(first);
   return 0;
 }
Exemplo n.º 23
0
Arquivo: 10327.cpp Projeto: fkrafi/UVa
int main()
{
	int i, n;
	while(scanf("%d", &n) != EOF)
	{
		for(i=1; i<=n; i++)
			scanf("%d", &a[i]);
		printf("Minimum exchange operations : %d\n", bubble_sort(n));
	}
	return 0;
}
int main(void)
{
    int array[] = {6, 5, 4, 3, 2, 1}; 
    int n = SIZE(array);
    
    print_array(array, n);
    bubble_sort(array, n);
    print_array(array, n);

    return 0;
}
Exemplo n.º 25
0
int main(void) {
	int input[ARR_LEN] = {2, 34, -6, 67, 12, 44, 12, 56, 90, 14};
	
	bubble_sort(input, ARR_LEN);
	//输出排序后的结果
	for (int i = 0; i < ARR_LEN; i++) {
		printf("%d ", input[i]);
	}
	
	return 0;
}
Exemplo n.º 26
0
int main(void)
{
	int num[5];
	init(num, 5);
	
	show(num, 5);
	bubble_sort(num, 5);
	show(num, 5);
	
	return 0;
}
Exemplo n.º 27
0
int main(void)
{
	int a[N];

	init_array(a, N);
	show_array(a, N);
	bubble_sort(a, N);
	show_array(a, N);

	return 0;
}
Exemplo n.º 28
0
int main()
{
  int array[] = { 1, 3, 2, 4, 5, 0, 44, 398, 333, 339 };
  int array_length = sizeof(array) / sizeof(int);
  bubble_sort(array, array_length);
  int i;
  for (i = 0; i < array_length; i++)
    printf("%d ", array[i]);
  puts("");
  return 0;
}
Exemplo n.º 29
0
int main() {
 int i,
	 cmp;
 //__CPROVER_assume(n < 5);
 i = init_array(5);
 bubble_sort(a,5);
 cmp = a[0];

 return 0;

}
int main () {
    int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
    int n = sizeof a / sizeof a[0];
    int i;
    for (i = 0; i < n; i++)
        printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
    bubble_sort(a, n);
    for (i = 0; i < n; i++)
        printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
    return 0;
}