Beispiel #1
0
void prueba()
  {
   int i,j;

   TVector v;
   v.frec=8000;
   v.tam=10000;
   v.x=(TMuestras)ourMalloc(sizeof(int16),v.tam,&(v.hx));
   ourFree(v.x,&(v.hx));

   paciencia();
   {
   HGLOBAL hglbNombre;
   HPCHAR caNombre=NULL;
   caNombre=(HPCHAR)ourMalloc(sizeof(char), MAX_LONG_NOMBRE, &hglbNombre);
   if (caNombre==NULL)
 	   {
      errorPRINTF("ERROR MALLOC");
      }
   ourHstrcpy(caNombre,"Juancho");
   if (ourFree(caNombre, &hglbNombre)!=NO_HAY_ERROR)
 	   {
      errorPRINTF("ERROR FREE");
      }
   }

   {
   HGLOBAL2D hglbNombres2d;
   HPPCHAR caNombres2d=NULL;
   caNombres2d=(HPPCHAR)ourCalloc2D(sizeof(char), MAX_NUM_NOMBRES, MAX_LONG_NOMBRE,
      &hglbNombres2d);
   if (caNombres2d==NULL)
 	   {
      errorPRINTF("ERROR MALLOC2D");
      }
   for (i=0; i<MAX_NUM_NOMBRES; i++)
      {
      ourHstrcpy(caNombres2d[i],"Juancho");
      }
   if (ourFree2D((HPPVOID)caNombres2d, &hglbNombres2d)!=NO_HAY_ERROR)
 	   {
      errorPRINTF("ERROR FREE2D");
      }
   paciencia();
   }

   {
   HGLOBAL3D hglbListasNombres3d;
   HPPPCHAR caListasNombres3d=NULL;
   caListasNombres3d=(HPPPCHAR)ourMalloc3D(sizeof(char), MAX_NUM_LISTAS, MAX_NUM_NOMBRES, MAX_LONG_NOMBRE,
      &hglbListasNombres3d);
   if (caListasNombres3d==NULL)
 	   {
      errorPRINTF("ERROR MALLOC3D");
      }
   for (i=0; i<MAX_NUM_LISTAS; i++)
      {
      for (j=0; j<MAX_NUM_NOMBRES; j++)
         {
         ourHstrcpy(caListasNombres3d[i][j],"Juancho");
         }
      }
   if (ourFree3D((HPPPVOID)caListasNombres3d, &hglbListasNombres3d)!=NO_HAY_ERROR)
 	   {
      errorPRINTF("ERROR FREE3D");
      }
   paciencia();
   }

  }
Beispiel #2
0
int main(){
	
	int fn,size;
	TpContato *tp = start();
	ListaContato *lista = init(), *lista_copy=init(), *lista_aux=init();
	TpContato *aux = start(), *copy = aux;

	clock_t cinicio, cfinal;
	
	system("clear");
	do{
		printf(
			"Escolha uma das opções abaixo:\n"
			"\t1) Criar Lista\n"
			"\t2) Cirar Vetor\n"
			"\t3) Ordenacao com Comb Sort\n"
			"\t4) Ordenacao com Merge Sort\n"
			"\t5) Sair\n\n"
		);

		scanf(" %d",&fn);
		switch(fn){
			case 1:
				system("clear");
				printf("Criar lista com quantos elementos?\n");
				scanf(" %d", &size);
				lista = createLista(size);
				printLista(lista);
				break;
			case 2:
				system("clear");
				printf("\t2) Cirar Vetor\n");

				tp = createVetor();
				fillVetor(tp);
				printVetor(tp);

				break;
			case 3:
				system("clear");
				printf("\t3) Ordenacao com Comb Sort\n");

				if (!isEmpty_vetor(tp)){
					copy = createVetor();
					vetcpy(copy, tp);

					cinicio = clock();
					combSort_vetor(copy);
					cfinal = clock();
					printf("\n");
					printVetor(copy);
					printf("Tempo: %f segundos.\n", (float)(cfinal-cinicio)/CLOCKS_PER_SEC);

					if(!isEmpty_vetor(copy)) free(copy);
				}
				if (!isEmpty_lista(lista)){
					lista_copy = listacpy(lista);

					cinicio = clock();
					combSort_lista(lista_copy,size);
					cfinal = clock();
					printf("\n");
					printLista(lista_copy);
					printf("Tempo: %f segundos.\n", (float)(cfinal-cinicio)/CLOCKS_PER_SEC);

					lista_copy = ourFree(lista_copy);
				}

				break;
			case 4:
				system("clear");
				printf("\t4) Ordenacao com Merge Sort\n");

				if (!isEmpty_vetor(tp)){
					aux = createVetor();
					copy = createVetor();
					vetcpy(copy, tp);

					cinicio = clock();
					mergeSort(copy, 0, MAX-1, aux);	// Vetor vai de 0-39
					cfinal = clock();

					printf("\n");
					printVetor(copy);
					printf("Tempo: %f segundos.\n", (float)(cfinal-cinicio)/CLOCKS_PER_SEC);

					if (!isEmpty_vetor(aux)) free(aux); 	// Liberando memória
					if (!isEmpty_vetor(copy)) free(copy); 	// Liberando memória
				}

				if (!isEmpty_lista(lista)){
					lista_copy = listacpy(lista);

					cinicio = clock();
					lista_aux = mergeSortList(lista_copy, 0, size-1, lista_aux);	
					cfinal = clock();

					printf("\n");
					printLista(lista_copy);
					printf("Tempo: %f segundos.\n", (float)(cfinal-cinicio)/CLOCKS_PER_SEC);
					
					lista_copy = ourFree(lista_copy);
					lista_aux = ourFree(lista_aux);

				}
				break;
			case 5:
				system("clear");
				printf("BYE!\n\n");
				break;
			default:
				system("clear");
				printf("Opção invalida!\n");
				break;
		}
	}while(fn != 5);

	if (!isEmpty_vetor(tp)) free(tp);

	lista = ourFree(lista);
	
	return 0;
}