int main (int argc, char* argv [])
{

	if ( argc < 2)
		perror("USAGE: filename number1 number2 .....");

	int count = argc - 1;
	int i = 0;

	// A char pointer point to all argument except the filename.
	char ** inputs = argv + 1;

	int * original_numbers = (int*) malloc(count * sizeof(int) );
	if ( original_numbers == NULL)
		perror("Memory error");

	for (i=0; i<count; i++){
		original_numbers[i] = atoi( inputs[i] );
	}

	test_sorting( original_numbers, count, sorted_order );
	test_sorting( original_numbers, count, reverse_order );

	free(original_numbers);

	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	if(argc < 2) die("USAGE: ex18 4 3 1 5 6");
	
	int count = argc - 1;
	int i = 0;
	char **inputs = argv + 1;

	int *numbers = malloc(count * sizeof(int));
	if(!numbers) die("Memory error.");

	for(i = 0; i < count; i++) {
		numbers[i] = atoi(inputs[i]);
	}

	// Pass in the wrong function for the compare_cb and see what the C compiler complains about.
	// test_sorting(numbers, count, Wrong_function);

	// Pass in NULL and watch your program seriously bite it.
	// test_sorting(numbers, count, NULL);

	test_sorting(numbers, count, sorted_order);
	test_sorting(numbers, count, reverse_order);
	test_sorting(numbers, count, strange_order);

	free(numbers);

	return 0;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
  if(argc < 2) die("USAGE; ex18 4 3 1 5 6");

  int count = argc - 1;
  int i = 0;
  char **inputs = argv + 1;

  int *numbers = malloc(count * sizeof(int));
  if(!numbers) die("Memory error.");

  for(i = 0; i < count; i++) {
    numbers[i] = atoi(inputs[i]);
  }
  
  // we're passing it three different sort functions as the third argument
  // where C just finds these functions and creates a pointer to their
  // address in memory. They can then be used without actually knowing what
  // the functions are
  test_sorting(numbers, count, sorted_order);
  test_sorting(numbers, count, reverse_order);
  test_sorting(numbers, count, strange_order);

  free(numbers);

  return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	// There must be at least two arguments
	if(argc < 2) die("USAGE: ex18 4 3 1 5 6");
	
	int count = argc - 1;
	int i = 0;
	char **inputs = argv + 1;
	
	// Allocate memory
	int *numbers = malloc(count * sizeof(int));

	// Make sure the memory has been allocated
	if(!numbers) die("Memory error.");

	for(i = 0; i < count; i++)
	{
		numbers[i] = atoi(inputs[i]);
	}

	test_sorting(numbers, count, sorted_order);
	test_sorting(numbers, count, reverse_order);
	test_sorting(numbers, count, strange_order);

	free(numbers);

	return 0;
}
Ejemplo n.º 5
0
Archivo: ex18.c Proyecto: Saisimon/tip
int main(int argc, char* argv[])
{
	if(argc < 2) 
		die("USAGE: ex18 4 3 1 5 6");
	
	int count = argc - 1;
	int i = 0;
	char **inputs = argv + 1;
	int *numbers = malloc(count * sizeof(int));

	if(!numbers)
		die("Memory error");

	for(i = 0; i < count ; i++)
	{
		numbers[i] = atoi(inputs[i]);
	}

	test_sorting(numbers, count, sorted_order);
	test_sorting(numbers, count, reverse_order);
	test_sorting(numbers, count, strange_order);
	// Question 3. test
	//test_sorting(numbers, count, NULL);

	free(numbers);

	return 0;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
    if (argc < 2) {
        die("USAGE: ex18 4 3 1 5 6");
    }
    
    int count = argc - 1;
    char **inputs = argv + 1;
    
    int *numbers = malloc(count * sizeof(int));
    assert(numbers != NULL); 
    
    for (int i = 0; i < count; i++) {
        numbers[i] = atoi(inputs[i]);
    }


    test_sorting(numbers, count, sorted_order);
    test_sorting(numbers, count, reverse_order);
    test_sorting(numbers, count, strange_order);

    free(numbers);
    
    return 0;
}
Ejemplo n.º 7
0
Archivo: ex18.c Proyecto: baloi/c_me
int main(int argc, char *argv[]) {
    if(argc < 2) die("Usage: ex18 4 3 2 1 6 7");

    int count = argc - 1;
    int i = 0;
    char **inputs = argv + 1;

    int *numbers = malloc(count * sizeof(int));

    for(i = 0; i < count; i++) {
        numbers[i] = atoi(inputs[i]);
    }

    test_sorting(numbers, count, sorted_order);
    test_sorting(numbers, count, reverse_order);

    free(numbers);
    return 0;
}
int main(int argc, char ** argv)
{
        if(argc < 2) die("USAGE: pro 4 54 54");

        int count = argc - 1;
        int i = 0;
        char **input = argv + 1;

        int *numbers = malloc(count * sizeof(int));
        if(!numbers) die("Memory error.");

        for(i = 0; i < count; i++) {
                numbers[i] = atoi(input[i]);
        }
        test_sorting(numbers, count, sorted_order);
        test_sorting(numbers, count, reverse_order);
        test_sorting(numbers, count, strange_order);

        free(numbers);
        return 0;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
	if (argc < 2)
		die("USAGE: ex18 4 3 1 5 6");

	int count = argc - 1;
	int i = 0;
	char **inputs = argv + 1;
	int *numbers = malloc(count * sizeof(int));
	
	if (!numbers)
		die("Memory error.");

	for (i = 0; i < count; i++) {
		numbers[i] = atoi(inputs[i]);
	}

	test_sorting(numbers, count, "Bubble Sort :: Normal ", bubble_sort, sorted_order);
	test_sorting(numbers, count, "Bubble Sort :: Reverse", bubble_sort, reverse_order);
	test_sorting(numbers, count, "Bubble Sort :: Strange", bubble_sort, strange_order);
	test_sorting(numbers, count, "Shell Sort  :: Normal ", shell_sort, sorted_order);
	test_sorting(numbers, count, "Shell Sort  :: Reverse", shell_sort, reverse_order);
	test_sorting(numbers, count, "Shell Sort  :: Strange", shell_sort, strange_order);

	free(numbers);

	return 0;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
  if(argc < 2) die("USAGE: ex18 1 5 7 8");

  int count = argc - 1;
  int i = 0;
  char **inputs = argv + 1;

  int *numbers = malloc(count * sizeof(int));
  if(!numbers) die("Memory error.");

  for(i = 0; i < count; i++){
    numbers[i] = atoi(inputs[i]);
  }

  printf("bubble Sorted  order >");
  test_sorting(numbers, count, bubble_sort, sorted_order);
  printf("bubble Reverse order >");
  test_sorting(numbers, count, bubble_sort, reverse_order);
  printf("bubble Weird   order >");
  test_sorting(numbers, count, bubble_sort, strange_order);

  printf("insertion Sorted  order >");
  test_sorting(numbers, count, insertion_sort, sorted_order);
  printf("insertion Reverse order >");
  test_sorting(numbers, count, insertion_sort, reverse_order);
  printf("insertion Weird   order >");
  test_sorting(numbers, count, insertion_sort, strange_order);

  free(numbers);

  return 0;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[]) {
    if (argc < 2)
        die("USAGE: ex18 5 2 1 6 3 4");

    int count = argc - 1;
    int i = 0;
    char **inputs = argv + 1;

    int *numbers = malloc(count * sizeof(int));
    if (!numbers)
        die("Memory error");

    for (i = 0; i < count; i++) {
        numbers[i] = atoi(inputs[i]);
    }

    puts("BUBBLE SORT");
    test_sorting(numbers, count, bubble_sort, sorted_order);
    test_sorting(numbers, count, bubble_sort, reverse_order);
    test_sorting(numbers, count, bubble_sort, strange_order);

    puts("INSERTION SORT");
    test_sorting(numbers, count, insertion_sort, sorted_order);
    test_sorting(numbers, count, insertion_sort, reverse_order);
    test_sorting(numbers, count, insertion_sort, strange_order);
    
    free(numbers);

    return 0;
}
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
  if (argc < 2) die("USAGE: ex18 4 3 1 5 8 2 3");

  int count = argc - 1;
  int i = 0;
  char **inputs = argv + 1;

  int *numbers = malloc(count * sizeof(int));
  if (!numbers) die("Memory error.");

  for (i = 0; i < count; i++) {
    numbers[i] = atoi(inputs[i]);
  }

  //Bubblesort
  printf("Bubble sort\n");
  test_sorting(numbers, count, sorted_order, bubble_sort);
  test_sorting(numbers, count, reverse_order, bubble_sort);
  test_sorting(numbers, count, strange_order, bubble_sort);
  printf("\n");

  //Quicksort
  printf("Quicksort:\n");
  test_sorting(numbers, count, sorted_order, quicksort);
  test_sorting(numbers, count, reverse_order, quicksort);
  test_sorting(numbers, count, strange_order, quicksort);
  
  free(numbers);

  return 0;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
	if(argc < 2) die("USAGE: ex18 4 3 1 5 6");

	int count = argc - 1;
	int i = 0;
	char **inputs = argv + 1;

	int *numbers = malloc(sizeof(int) * count);
	if(!numbers) die("Memory error.");

	for(i = 0; i < count; i++) {
		numbers[i] = atoi(inputs[i]);
	}

	puts("\nUsing Bubble Sort method\n");

	puts("Sorted order");
	test_sorting(numbers, count, sorted_order, bubble_sort);
	puts("Reverse order");
	test_sorting(numbers, count, reverse_order, bubble_sort);
	puts("Strange order");
	test_sorting(numbers, count, strange_order, bubble_sort);

	puts("\nUsing Comb Sort method\n");

	puts("Sorted order");
	test_sorting(numbers, count, sorted_order, comb_sort);
	puts("Reverse order");
	test_sorting(numbers, count, reverse_order, comb_sort);
	puts("Strange order: causes infinite loop, don't use with Comb Sort...");
	//test_sorting(numbers, count, strange_order, comb_sort);

	free(numbers);	

	return 0;
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
	if(argc <2) die("Usage: ./example18 4 5 2 6 9");
	
	int count = argc - 1;
	int i = 0;
	char **inputs = argv + 1;
	
	int *numbers = malloc(count * sizeof(int));
	if(!numbers) die("Memory error.");
	
	for(i = 0; i < count; i++) {
		numbers[i] = atoi(inputs[i]);
	}
	
	test_sorting(numbers, count, sorted_order);
	test_sorting(numbers, count, reverse_order);
	test_sorting(numbers, count, strange_order);
	
	free(numbers);
	
	return 0;
	
}
Ejemplo n.º 15
0
int main(int argc, char *argv[]) {

  if(argc < 2) die("Usage: twelveth 1 3 5 4 2 6");

  int count = argc - 1;
  int i = 0;
  char **inputs = argv + 1;

  int *numbers = malloc(count * sizeof(int));
  if(!numbers) die("Memory error");

  for(i = 0; i < count; i++) {
    numbers[i] = atoi(inputs[i]);
  }

  test_sorting(numbers, count, sorted_order, selection_sort);
  test_sorting(numbers, count, sorted_order, bubble_sort);
  test_sorting(numbers, count, strange_order, selection_sort);
  test_sorting(numbers, count, strange_order, bubble_sort);

  free(numbers);

  return 0;
}
Ejemplo n.º 16
0
int main(int args, char *arg[]) {

	list_t *list = NULL;
	list = test_create();
	test_insert(list);
	test_delete(list);
	test_examine(list);
	test_distroy(&list);
	list = test_create();	
	test_sorting(list);
	test_distroy(&list);
    test_concat_lists();
	test_merge_lists();
	test_reverse_lists();

	exit (EXIT_SUCCESS);
}
Ejemplo n.º 17
0
int main(int argv, char *args[]) 
{

    if(argv != VALID_ARGUMENTS) 
	{
        fprintf(stderr, "Invalid arguments: %s \n", args[1]);
        exit(EXIT_FAILURE);
    }

    int num_of_elements = atoi(args[1]);
    int* arr;
    arr = xcalloc(num_of_elements, sizeof(int));

	// populates array with random numbers
    input(arr, num_of_elements);

    sort(arr, num_of_elements);
	
    test_sorting(arr, num_of_elements);

    free(arr);

    exit(EXIT_SUCCESS);
}