//-------------------------Função Principal------------------- int main(){ int menu, dado, i; TpContato *vect = NULL, *control; TpList *head = NULL, *tail, *manipulation; /* Ponteiro do tipo listaconjunto para armazenarem: head - Primeiro conjunto criado. Indica conjunto inicio da fila; tail - Ultimo conjunto criado. Indica conjunto no final da fila; conjuntoatual - Manipulação; */ do{ printf("\nTrabalho_NP2\n\n1 - Criar Lista..\n2 - Criar Vetor..\n3 - Algoritmo a ser estudado..\n"); printf("4 - Método logarítmico..\n0 - Sair\n"); scanf("%d", &menu); __fpurge(stdin); getchar(); printf("\033[H\033[J"); //Limpar Tela no Linux //system("cls");// Limpar tela no Windows switch (menu) { case 1: if(head == NULL){ printf("How many contacts do you want to create?\n"); scanf("%d", &dado); head = createList(dado); printf("List created sucessfully!\n"); printList(head); } else{ printf("List already has been created!\n"); } break; case 2: if(vect == NULL){ vect = createVector(); printf("Vector created sucessfully!\n\n"); printVector(vect); } else{ printf("Vector already has been created!\n"); } break; case 3: control = copyVector(vect); cocktailSort(control); printVector(control); break; } }while(menu != 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; }