コード例 #1
0
ファイル: hw5functions.cpp プロジェクト: cbomgit/hw5
void run_all_except_insertion(int random_arr[], int sorted_arr[], int length)
{
    //copy of the input arrays to keep them intact
    int random_arr_copy[length];
    int sorted_arr_copy[length];
    
    //double arrays with running times
    double sorted_times[4];
    double random_times[4];
    
    //clock_t struct returned by the clock function for start and end times
    clock_t start, end;
    int ndx = 0;
    
    copy_array(random_arr, random_arr_copy, length);    
    copy_array(sorted_arr, sorted_arr_copy, length);
    
    //run quicksort getting elapsed time for each
    start = clock();
    quick_sort(random_arr_copy, 0, length - 1);
    end = clock();
    copy_array(random_arr, random_arr_copy, length);
    random_times[ndx] = ((double)(end - start)) / CLOCKS_PER_SEC;
    
    start = clock();
    quick_sort(sorted_arr_copy, 0, length - 1);
    end = clock();
    copy_array(sorted_arr, sorted_arr_copy, length);
    sorted_times[ndx++] = ((double)(end - start)) / CLOCKS_PER_SEC;
    
    //run heapsort
    start = clock();
    heap_sort(random_arr_copy, length, length);
    end = clock();
    copy_array(random_arr, random_arr_copy, length);
    random_times[ndx] = ((double)(end - start)) / CLOCKS_PER_SEC;
    
    start = clock();
    heap_sort(sorted_arr_copy, length, length);
    end = clock();
    copy_array(sorted_arr, sorted_arr_copy, length);
    sorted_times[ndx++] = ((double)(end - start)) / CLOCKS_PER_SEC;

    
    //run merge sort
    start = clock();
    merge_sort(random_arr_copy, 0, length - 1);
    end = clock();
    copy_array(random_arr, random_arr_copy, length);
    random_times[ndx] = ((double)(end - start)) / CLOCKS_PER_SEC;
    
    start = clock();
    merge_sort(sorted_arr_copy, 0, length - 1);
    end = clock();
    copy_array(sorted_arr, sorted_arr_copy, length);
    sorted_times[ndx++] = ((double)(end - start)) / CLOCKS_PER_SEC;
    
    output_table(random_times, sorted_times);
}
コード例 #2
0
ファイル: functions.c プロジェクト: annnca/PT
void heap_sort(node_heap *root, int *vec, int *size)
{
	if (root->l != 0)
		heap_sort(root->l, vec, size);

	*size = *size + 1;
	vec[*size] = root->data;

	if (root->r != 0)
		heap_sort(root->r, vec, size);
}
コード例 #3
0
ファイル: main.c プロジェクト: barosl/disk-sort
static int process(const char *fpath_bin, const char *fpath_uniq, const char *fpath_text) {
#if INTERFACE_TYPE == 0
    FILE *fp_bin = fopen(fpath_bin, "r+b");
    if (!fp_bin) return -1;
    fseek(fp_bin, 0, SEEK_END);

//	sel_sort(ftell(fp_bin)/sizeof(rec_t), sizeof(rec_t), fp_bin, rec_stdio_getter, rec_stdio_setter, rec_stdio_cmp);
    heap_sort(ftell(fp_bin)/sizeof(rec_t), sizeof(rec_t), fp_bin, rec_stdio_getter, rec_stdio_setter, rec_stdio_cmp);

    fclose(fp_bin);
#elif INTERFACE_TYPE == 1 || INTERFACE_TYPE == 2 || INTERFACE_TYPE == 3
    int fd_bin = open(fpath_bin, O_RDWR);
    if (fd_bin == -1) return -1;

#if INTERFACE_TYPE == 2
    off_t f_len = lseek(fd_bin, 0, SEEK_END);

    lseek(fd_bin, 0, SEEK_SET);
    rec_t *rec_l = (rec_t*)mmap(NULL, f_len, PROT_WRITE, MAP_SHARED, fd_bin, 0);

    heap_sort(f_len/sizeof(rec_t), sizeof(rec_t), rec_l, rec_mem_getter, rec_mem_setter, rec_mem_cmp);

    munmap(rec_l, f_len);
#elif INTERFACE_TYPE == 3
    off_t f_len = lseek(fd_bin, 0, SEEK_END);
    rec_t *rec_l = (rec_t*)malloc(f_len);

    lseek(fd_bin, 0, SEEK_SET);
    read(fd_bin, rec_l, f_len);

    heap_sort(f_len/sizeof(rec_t), sizeof(rec_t), rec_l, rec_mem_getter, rec_mem_setter, rec_mem_cmp);

    lseek(fd_bin, 0, SEEK_SET);
    write(fd_bin, rec_l, f_len);

    free(rec_l);
#else
    heap_sort(lseek(fd_bin, 0, SEEK_END)/sizeof(rec_t), sizeof(rec_t), (void*)fd_bin, rec_posix_getter, rec_posix_setter, rec_posix_cmp);
#endif

    close(fd_bin);
#endif

    FILE *fp_uniq = uniq(fpath_bin, fpath_uniq);

    write_to_text(fpath_text, fp_uniq);

    fclose(fp_uniq);

    return 0;
}
コード例 #4
0
ファイル: heap_sort.c プロジェクト: sachinboban/algos
int main()
{
	int index;
	heap_t heap;

	scanf("%d", &heap.size);
	heap.heap_size = heap.size;

	heap.array = (int *)malloc(sizeof(int) * heap.size);
	if(!heap.array) {
		printf("ERROR: malloc()\n");
		return 0;
	}
	memset(heap.array, 0, sizeof(int) * heap.size);

	for(index = 0; index < heap.size; index += 1)
		scanf("%d", &(heap.array[index]));

	printf("\nInput array: ");
	for(index = 0; index < heap.size; index += 1)
		printf("%d ", heap.array[index]);

	heap_sort(heap);
	
	printf("\nSorted array: ");
	for(index = 0; index < heap.size; index += 1)
		printf("%d ", heap.array[index]);

	free(heap.array);
	return 0;
}
コード例 #5
0
void run_sorts(buf *buf) {
	fill(buf);

	while(1) {
		int r = rand_from(0, 4);

		fisher_yates_shuffle(buf, 0, buf->length-1);

		switch (r) {
		case 0:
			printf("Insertion Sort.\n");
			insertion_sort(buf, 0, buf->length-1);
			break;
		case 1:
			printf("Quick Sort.\n");
			quicksort(buf, 0, buf->length-1);
			break;
		case 2:
			printf("Heap Sort.\n");
			heap_sort(buf, 0, buf->length-1);
			break;
		case 3:
			printf("Selection Sort.\n");
			selection_sort(buf, 0, buf->length-1);
			break;
		case 4:
			printf("Merge Sort.\n");
			merge_sort(buf, 0, buf->length-1);
			break;
		}
	}
}
コード例 #6
0
int main()
{
    int select, size, *test;
    while (select = menu())
    {
        size = get_integer("Array size");
        while(size <= 0)
            size = get_integer("Array size must bigger then zero");

        test = init_array(test, size);

        printf("Before sort:\n");
        print_array(test, size);
        switch (select) {
            case 1:
                insertion_sort(test,size);
                break;
            case 2:
                shell_sort(test, size);
                break;
            case 3:
                heap_sort(test, size);
                break;
            case 4:
                merge_sort(test, size);
                break;
            case 5:
                quick_sort(test, size);
                break;
        }
        printf("After sort:\n");
        print_array(test, size);
    }
   return 0;
}
コード例 #7
0
ファイル: sort.c プロジェクト: B-Rich/taurus
void main(void) {
  int arr[10]={9,8,70,6,5,4,3,2,1,0};
  heap_sort(arr,10,1);
  int i;
  for (i = 0; i < 10; i++)
    printf("%d ",arr[i]);
}
コード例 #8
0
ファイル: driver.c プロジェクト: Maithem/algorithms-for-fun
int main() {
    
  u_i len = 12;
  int arr[12] = {2, 13, 12, 16, 15, 4, 17, 8, 1, 18, 14, 9};
  int *temp1 = copy(arr, len);
  insertion_sort(temp1, len);
  int *temp2 = copy(arr, len);
  quick_sort(temp2, len);
  int *temp3 = copy(arr, len);
  merge_sort(temp3, len);
  int *temp4 = copy(arr, len);
  selection_sort(temp4, len);
  int *temp5 = copy(arr, len);
  counting_sort(temp5, len);
  int *temp6 = copy(arr, len);
  heap_sort(temp6, len);
  int *temp7 = copy(arr, len);
  radix_sort(temp7, len);
  
  bool eq = equal(temp1, temp2, len) &
            equal(temp2, temp3, len) &
            equal(temp3, temp4, len) &
            equal(temp4, temp5, len) &
            equal(temp5, temp6, len) &
            equal(temp6, temp7, len);
            
  printf("\x1B[32m""Equal arrays :%s\n""\033[0m", eq ? "true" : "false");
  
  // Free all arrays allocated.
}
コード例 #9
0
int main()
{
    const int LEN = 10000001;
    int i;
    int* arr = (int*)malloc(sizeof(int) * LEN);

    int input_range_start = 0;
    int input_range_end = 1333;

    srand(time(NULL));
    for (i = 0; i < LEN; i++)
    {
        arr[i] = input_range_start + rand() % (input_range_end - input_range_start);
    }

    //printf("is sorted? %d\n", is_sorted(arr, LEN));

    //print_arr(arr, LEN);
    time_t start, stop;

    start = clock();
    heap_sort(arr, LEN);
    stop = clock();

    //print_arr(arr, LEN);
    printf("time: %fs\n", (double)(stop - start) / CLOCKS_PER_SEC);
    printf("is sorted? %d\n", is_sorted(arr, LEN));

    return 0;
}
コード例 #10
0
ファイル: heapsort.c プロジェクト: vincentlooi/C_stuff
int main() {
	int *arr = malloc(sizeof(int) * MAX);
	int i;
	for (i = 0; i < MAX; i++) {
		arr[i] = rand();
	}
//	{3,5,2,1,6,8,3,5,42,234,23,22,15,7,9,0};
	i = 0;
	printf("BEFORE:\n");
	for (i = 0; i < MAX; i++) {
		printf("%d\n", arr[i]);
	}

	heap_sort(&arr, MAX);

//	i = 0;
//	printf("\nAFTER:\n");
//	for (i = 0; i < MAX; i++) {
//		printf("%d\n", arr[i]);
//	}

	free(arr);

	return 0;
}
コード例 #11
0
ファイル: test.c プロジェクト: Fransunshine/chapter_linux_git
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 ;
}
コード例 #12
0
int main()
{
    int testcase[] = {
        100, 99, 98, 97, 96, 95, 94, 93, 92, 91,
        90,  89, 88, 87, 86, 85, 84, 83, 82, 81,
        80,  79, 78, 77, 76, 75, 74, 73, 72, 71,
        70,  69, 68, 67, 66, 65, 64, 63, 62, 61,
        60,  59, 58, 57, 56, 55, 54, 53, 52, 51,
        50,  49, 48, 47, 46, 45, 44, 43, 42, 41,
        40,  39, 38, 37, 36, 35, 34, 33, 32, 31,
        30,  29, 28, 27, 26, 25, 24, 23, 22, 21,
        20,  19, 18, 17, 16, 15, 14, 13, 12, 11,
        10,   9,  8,  7,  6,  5,  4,  3,  2,  1};
    int i;
    for(i = 0; i< sizeof(testcase)/sizeof(testcase[0]); i++)
    {
        printf("%d ", testcase[i]);
    }
    printf("\n");

    heap_sort(testcase, sizeof(testcase)/sizeof(testcase[0]));

    for(i = 0; i< sizeof(testcase)/sizeof(testcase[0]); i++)
    {
        printf("%d ", testcase[i]);
    }
    printf("\n");
    return 0;
}
コード例 #13
0
result_t sort(list_t *list)
{
	data_t *list_data;
	len_t size;

	size = length(list);  
	if(size == 0)
	{
		return (ERROR);
	} 
	else if(size == 1) 
	{
		return (SUCCESS);
	}

	list_data = list_to_array(list, size);
	if(size < INSERTION_SHORT_SIZE)
	{
		insertion_sort(list_data, size);
	}
	else
	{
		heap_sort(list_data, size);
	}
	list_t *temp = array_to_list(list_data, size);
	list -> next = temp;
	free(list_data);
	//TO-DO : delete list
	return (SUCCESS);
}
コード例 #14
0
ファイル: heapsort.c プロジェクト: morining/forrest
/******************************************************************************
 * MAIN
 ******************************************************************************/
int main(int argc, char * argv[])
{
    int A[MAX_NUM_NR];
    char * filename_unsorted = get_filename(argc, argv);
    char * filename_sorted = get_sorted_filename(filename_unsorted);

    int n = get_A(A, MAX_NUM_NR, filename_unsorted);

    print_A(A, n, "original:");
    heap_sort(A, n);
    print_A(A, n, "sorted:");

    assert(verify_A(A, n, filename_sorted));

    /* priority queue */
    int heapsize = n;
    build_max_heap(A, heapsize);
    ______________________________(A, n, heapsize, "===============\\nafter build_max_heap\\n===============");

    printf("heap_maximum: %d\n", heap_maximum(A, heapsize));

    printf("heap_extract_max: %d\n", heap_extract_max(A, &heapsize));
    print_A(A, heapsize, "after heap_extract_max");
    ______________________________(A, n, heapsize, "===============\\nafter heap_extract_max\\n===============");

    heap_increase_key(A, heapsize, 3, 88);
    print_A(A, heapsize, "after heap_increase_key");
    ______________________________(A, n, heapsize, "===============\\nafter heap_increase_key\\n===============");

    max_heap_insert(A, n, &heapsize, 97);
    print_A(A, heapsize, "after max_heap_insert");
    ______________________________(A, n, heapsize, "===============\\nafter max_heap_insert\\n===============");

    return 0;
}
コード例 #15
0
ファイル: main.c プロジェクト: zhangzewen/Algorithms
int main(int argc, char **argv)
{
	vector *c = NULL;
	int v1 = 4;
	int v2 = 1;
	int v3 = 3;
	int v4 = 2;
	int v5 = 16;
	int v6 = 9;
	int v7 = 10;
	int v8 = 14;
	int v9 = 8;
	int v10 = 7;
	c = vector_create();	

	c->push(c, (void *)(&v1 ));
	c->push(c, (void *)(&v2 ));
	c->push(c, (void *)(&v3 ));
	c->push(c, (void *)(&v4 ));
	c->push(c, (void *)(&v5 ));
	c->push(c, (void *)(&v6 ));
	c->push(c, (void *)(&v7 ));
	c->push(c, (void *)(&v8 ));
	c->push(c, (void *)(&v9 ));
	c->push(c, (void *)(&v10));
	Print(c, visit);
	make_heap(c, compare);
	Print(c, visit);
	printf("\n===============================\n");
	heap_sort(c, compare);
	Print(c, visit);
	vector_destroy(&c, NULL);
	return 0;
}
コード例 #16
0
ファイル: heap-sort.c プロジェクト: fuzzyBatman/algorithms
// program start
int main(int argc, char const *argv[])
{
	int arr[MAX_SIZE] = {0, 2, 5, 1, 6, 4, 3, 9, 7, 8};		// first element is unused
	int size = 9;
	
	heap_sort(arr, size);			// call to heap sort
	print_array(arr, 1, 9);
	return 0;
}
コード例 #17
0
ファイル: heap.c プロジェクト: hitchiker42/my-code
void heap_sort_generic(void **input, size_t len, cmp_fun cmp) {
    binary_heap *heap = alloca(sizeof(binary_heap));
    heap->heap = input;
    heap->cmp = cmp;
    heap->len = len;
    heap->mem = len;
    heap_sort(heap);
    return;
}
コード例 #18
0
int main()
{
	Sqlist *L=(Sqlist *)malloc(sizeof(Sqlist));
	initial(L);
	print(L);
	heap_sort(L);
	print(L);
	return 0;		
}
コード例 #19
0
ファイル: heap_sort.c プロジェクト: damnever/Note
int
main()
{
    int arr[] = {4, 1, 3, 2, 16, 9, 10, 14, 8, 7};
    int arr2[] = {5, 13, 2, 25, 7, 17, 20, 8, 4};
    int len = arr_len(arr);
    int len2 = arr_len(arr2);

    print_arr(arr, len);
    heap_sort(arr, len);
    print_arr(arr, len);

    print_arr(arr2, len2);
    heap_sort(arr2, len2);
    print_arr(arr2, len2);

    return 0;
}
コード例 #20
0
//本例程中,从数组的第二个数a[1]开始进行排序
int main()
{
    int a[] = {5, 7, 2, 3, 8, 5,6, 9};
    heap_sort(a,LEN-1);
    int k;
    for(k = 1; k < LEN; k++)
    printf("%d  ", a[k]);
    return 0;
}
コード例 #21
0
int main()
{
	size_t number_of_players = 0;
	scanf("%"SCNi32, &number_of_players);
	Player *players = (Player*)calloc(number_of_players, sizeof(Player));//удалить (int*)
	if (!players)
		return 1;
	for (size_t i = 0; i < number_of_players; ++i)// использовать size_t для индексации
	{
		players[i].number = i + 1;
		scanf("%"SCNi32, &players[i].data);
	}
	heap_sort(players, number_of_players, ASCENDING);

	int i = 0, j = 1;
	int boss_player = i;
	int less_player = i;
	int64_t cur_command = players[0].data;
	int64_t max_command = cur_command;
	while (j < number_of_players){
		if (players[j].data <= (players[i].data + players[i + 1].data)){
			cur_command += players[j].data;
			if (cur_command > max_command){
				less_player = i;
				boss_player = j;
				max_command = cur_command;
			}
			j++;
		}
		else{
			cur_command -= players[i].data;
			i++;
		}
	}
	printf("%"PRIi64"\n", max_command);
	Player *sort_player_command = (Player*)calloc(boss_player - less_player + 1, sizeof(Player));
	for (size_t i = less_player, count = 0; i <= boss_player; i++, count++)
		sort_player_command[count].data = players[i].number;
	heap_sort(sort_player_command, boss_player - less_player + 1, ASCENDING);
	for (size_t i = 0; i < boss_player - less_player + 1; i++)
		printf("%"PRIi32"%c", sort_player_command[i].data, (i != boss_player - less_player) ? ' ' : '\n');
	system("pause");
	return 0;
}
コード例 #22
0
ファイル: main.c プロジェクト: murongruomeng/algorithm
int
main(int argc, char **argv)
{

    // list *list = list_create();
    // int a = 5;
    // int b = 4;
    // int c = 3;
    // int d = 2; 
    // int e = 1;
    // int f = 0;

    // int j = 10;
    // list_add_node_tail(list, &a);
    // list_add_node_tail(list, &b);
    // list_add_node_tail(list, &c);
    // list_add_node_tail(list, &d);
    // list_add_node_tail(list, &e);
    // list_add_node_tail(list, &f);

    // list_set_match_method(list, match);

    // list_node *node = list_search_key(list, &f);
    // list_insert_node(list, node, &j, 1);
    // list_del_node(list, node);

    // printf("%ld\n", list_length(list));
    // list_iterator *iter = list_get_iterator(list, AL_START_HEAD);
    // list_node *current;
    // while ((current = list_next(iter))) 
    //     printf("%d ", *((int *)current->data));

    // printf("\n");
//    int RANGE_MAX = 100;
//
//    int len = 21;
//    int a[len];
//    get_random_int_array(a, len, RANGE_MAX);
//     printf("Before sort: ");
//    print_array(a, len);
//    merge_sort(a,0,len-1);
//    printf("After  sort: ");
//    print_array(a, len);

//    int a[] = {16, 4, 10, 14, 7, 9, 3, 2, 8, 1};
    int a[] = {4, 1, 3, 2, 16, 9, 10, 14, 8, 7};

    int len = 10;
    printf("Before sort: ");
    print_array(a, len);
    heap_sort(a, len);
    printf("After  sort: ");
    print_array(a, len);

    return EXIT_SUCCESS;
}
コード例 #23
0
ファイル: test_heap.c プロジェクト: samrat-gavale/prep
int main(void)
{
	int arr[10] = {2,4,3,1,8,6,9,5,7,10};
	//int arr[2] = {4,2};
	print_array(arr,(sizeof(arr)/sizeof(int)));
	heap_sort(arr,sizeof(arr)/sizeof(int));
	printf("\n");
	print_array(arr,(sizeof(arr)/sizeof(int)));
	return 0;
}
コード例 #24
0
ファイル: heap.c プロジェクト: njdragonfly/CLRS
int main()
{
	int h[]={21,12,33,34,54,63,77};

	heap_sort(h,sizeof(h)/sizeof(int));
	print_int_array(h,0,sizeof(h)/sizeof(int)-1);

	return 0;

}
コード例 #25
0
ファイル: maxheap.c プロジェクト: oxnz/algorithms
int main() {
    int a[13];
	int n = sizeof(a)/sizeof(a[0]);
    random_array(a, n);
    print_array(a, n);
    heap_sort(a, n);
    print_array(a, n);

	return 0;
}
コード例 #26
0
ファイル: 3-18-b.c プロジェクト: darthvade/PersonalExercise
int main() {

	int input[] = {3, 5, 6, 1, 2, 6, 9, 4, 8};

	int len = sizeof(input) / sizeof(int);
	
	heap_sort(input, len);

	return 0;
}
コード例 #27
0
ファイル: heap_sort.c プロジェクト: ManBeMe/algorithms
int main(int argc, char argv[])
{
    int arr[] = {3, 5, 2, 7, 0};
    int len = sizeof(arr)/sizeof(int);

    heap_sort(arr, len, 5);
    print_res(arr, len);

    return 0;
}
コード例 #28
0
ファイル: 0000-main.c プロジェクト: stillcold/src
int main(void){

    init_heap_and_dp();

#ifdef DEBUG_MODE
    print_heap(HEAP_MAX_LENGTH);
#endif

    /* Heap sort */
    mark_start();
    heap_sort(HEAP_MAX_LENGTH);
    mark_stop();
    get_time_difference(&time_count);

    printf("Time taken by heap sort: %d\n",(int)time_count.tv_usec);

#ifdef DEBUG_MODE
    print_heap(HEAP_MAX_LENGTH);
#endif

#ifdef DEBUG_MODE
    printf("Sort with bitmap.\n");
#endif

    /* Bitmap sort algorithm */
    mark_start();
    for (i = 1; i < HEAP_MAX_LENGTH; i++){
        set_bit_in_map((unsigned)array[i]);
    }
    mark_stop();
    get_time_difference(&time_count);

    printf("Time taken by bitmap sort: %d\n",(int)time_count.tv_usec);

#ifdef DEBUG_MODE
    show_bitmap();
    for (i = 1; i < MAP_MAX_LENGTH; i++){
        if (check_bit_in_map(i)){
            printf("%u\t", i);
        }
    }
    printf("\n");
#endif

    /* Algorithm: dp */
    printf("This is dp result: %d\n", dp_demo(5));

    /* Algorithm: BP(artificial network) */
    test_aritificial_neural_network();

    /* Algorithm: manacher */
    test_manacher();

    return 0;
}
コード例 #29
0
ファイル: sort_test.c プロジェクト: haow1990/algorithms
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;
}
コード例 #30
0
int main()
{
	int a[100],n,i;
	printf("enter size of the array :");
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	heap_sort(a,n);
	printf("Sorted array : ");	
	for(i=0;i<n;i++)
	printf("%d ",a[i]);
}