Exemple #1
0
int main(int argc, char *argv[]) {
	
	int i = 0, sumx, sumc;
	List headL, headP, L, P, prevL, prevP, ret, headRet;
	
	// P1 10X^1000 + 5X^14 + 1
	// p2 3X^1990  - 2X^1492 + 11X + 5
	int example1[] = {10, 1000, 5, 14, 1, 0};
	int example2[] = {3, 1990, -2, 1492, 22, 14, 11, 1, 5, 0};
	
	prevL = headL = malloc(sizeof(struct Node));
	prevP = headP = malloc(sizeof(struct Node));
	ret = headRet = malloc(sizeof(struct Node));
	prevL->next = NULL;
	prevP->next = NULL;
	
	while (i <= 4) {
		Insert(example1[i], example1[i+1], headL, prevL);
		prevL = prevL->next;
		i+=2;
	}
	i = 0;
	while (i <= 8) {
		Insert(example2[i], example2[i+1], headP, prevP);
		prevP = prevP->next;
		i+=2;
	}
	printList(headL);
	printList(headP);
	
	L = headL->next;
	P = headP->next;

	ret->next = NULL;
	i = 0;
	while (L != NULL) {
		while (P != NULL) {
			sumc = L->c * P->c;
			sumx = L->x + P->x;
			ret = binarySort(sumx, sumc, headRet, i);
			P = P->next;
			count++;
			if (ret != NULL) {
				Insert(sumc, sumx, headRet, ret);	
				i++;
			}
		}
		L = L->next;
		P = headP->next;
	}
	printList(headRet);
	printf("\n\n count is [%d].", count);
	return 1;
}
int main(){
	int a[] = {1,4,5,6,7,89,3434,34345};
	printf("re = %d\n",binarySort(a,sizeof(a)/sizeof(a[0]),89));
	printf("re = %d\n",binarySort(a,sizeof(a)/sizeof(a[0]),67));
	return 0;
}
int main() 
{
    const unsigned long int N = 100;
    
    std::cout << N << std::endl;

    srand((int) time(NULL));
    
    int * a = new int[N];
    int * aux = new int[N];

    copiaNumeros(a,N);
    
    for (int i = 0; i < N; ++i) 
    {
        aux[i] = a[i];
    }

    auto begin = std::chrono::high_resolution_clock::now();
    bubbleSort(a, N);
    auto end = std::chrono::high_resolution_clock::now();
    auto tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Bubble: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    cocktailSort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Cocktail: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    insertionSort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Insertion: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    bucketSort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Bucket: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    countingSort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Counting: "<<tiempo.count()<<std::endl;

    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    mergeSort(a, 0, N-1, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Merge: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    radixSort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Radix: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    shellSort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Shell: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    selectionSort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Selection: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    quickSort(a, 0, N-1);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Quick: "<<tiempo.count()<<std::endl;
    
    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    heap_sort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Heap: "<<tiempo.count()<<std::endl;

    for( int i = 0; i<N; i++)
    {
        a[i] = aux[i];
    }
    begin = std::chrono::high_resolution_clock::now();
    binarySort(a, N);
    end = std::chrono::high_resolution_clock::now();
    tiempo = std::chrono::duration_cast<std::chrono::microseconds>(end-begin);
    std::cout<<"Binary: "<<tiempo.count()<<std::endl;

    delete a;
    delete aux;

    return 0;
}