Exemple #1
0
int main()
{
    int a[7]={9,4,5,6,7,2,3};
    insertsort(a,7);
    bubblesort(a,7);
    selectsort(a,7);
}
Exemple #2
0
/*
    Test for callback with selectsort, can deal with int, strings
*/
int
main(void)
{
    int iary[MAX]     = {8, 7, 3, 1, 10, 4, 2, 5, 6, 9};
    char *strary[MAX] = {
        "abcd", "abc", "bcda", "cd", "ca", "ad", "ac", "abcd", "bcda", "d"
    };
    
    selectsort((void *)iary, sizeof(iary) / sizeof(iary[0]), sizeof(iary[0]), compare_int);

    //bug when dealing with string
    selectsort((void *)strary, sizeof(strary) / sizeof(strary[0]), sizeof(strary[0]), compare_str);


    return 0;
}
Exemple #3
0
int main()
{
 int i;
 int a[]={1,6,4,8,5};
 selectsort(a,5);
 for(i=0;i<5;i++)
	 printf("%3d",a[i]);
 printf("\n");
 return 0;

}
Exemple #4
0
int main()
{
    int i,a[10] = {2,5,6,3,7,8,0,9,12,1};        
    printf("The data array is:\n") ;
    for(i=0;i<10;i++)                        /*显示原序列之中的元素*/
        printf("%d ",a[i]);

    selectsort(a,10);                         /*执行选择排序*/
	printf("\nThe result of selection sorting for the array is:\n");
    for(i=0;i<10;i++)
        printf("%d ",a[i]);                        /*输出排序后的结果*/
	printf("\n");
	
	return 0;
}
Exemple #5
0
int main()
{
	int a[10]={10,1,2,4,7,8,3,9,5,6};
	display(a,10);
	printf("the samllest tumple is:%d\n",findsamll(a,10));
	selectsort(a,10);
	printf("after selectsort,a[]:");
	display(a,10);
	int b[10]={10,9,8,7,2,3,5,4,1,6};
	printf("after insersort,b[]:");
	insersort(b,10);
	display(b,10);
	int c[10]={18,29,30,38,8299,267,378,29,83,0};
	printf("after bubblesort,c[]:");
	bubblesort(c,10);
	display(c,10);
	return 0;
}
Exemple #6
0
int main()
{
	int array[] = {3, 5, 9, 2, 4, 1, 8, 7, 6};
	int len = sizeof(array)/sizeof(array[0]);

	printf("Before: ");
	print_array(array, len);
	printf("\n");

	selectsort(array, len);
	printf("\n");

	printf("After:  ");
	print_array(array, len);

	getchar();
	return 0;
}
Exemple #7
0
void quicksortrec(int low, int high, int m, int *p)
{
	while (low < high) {
		if (m >= (high - low)) {
			selectsort(low, high, p); 
			return;
			}
		int q = partition(low, high, p);
		if ((low - q) < (high - q)) {
			quicksortrec(low, q-1, m, p);
			low = q+1;
		}
		else {
			quicksortrec(q + 1, high, m, p);
			high = q-1;
		
		}
	}
}
int main() {
	int n, i;
	clock_t start, runtime;
	printf("Number of items = ");
	while (scanf("%i", &n)) {
		if (n > nmax) {printf("Number too large. Try again: ");
		continue; 
	}//end of main
	printf("Generating %d random numbers in the range 0..%d.n", n,RAND_MAX);
	for (i = 1; i <= n; i++) A[i] = rand();
		printf("Beginning selection sort of %d items\n", n);

	start = clock();
	selectsort(n);
	runtime = clock() - start;
	printf("Done. Time = %.4f seconds.\n",(double)runtime/(double)CLOCKS_PER_SEC);
	printf("Number of items = ");
	}
	return 0;
}//end of main
Exemple #9
0
void main(){
    int arr[5] = { 4,2,3,1,5 };
    selectsort(arr, 5);
    display(arr, 5);

}