예제 #1
0
int mediane(int * tab, int t_long){
	int ind;
	
	tri_bulle(tab, t_long);
	ind = t_long/2 + t_long%2 - 1;
	return tab[ind];
}
예제 #2
0
파일: whatSize.c 프로젝트: MaximeGir/ls-
/*
 * fonction qui retourne un tableau d'entier trier en ordre décroissant.
 * @param tab un tableau de structure Element 
 * @param size un entier représentant la taille de tab 
 */
void get_tab_trier(struct Element tab[], int size)
{
   int tableau_taille[size];
  
   for(int i = 0; i<size; i++)
    tableau_taille[i] = tab[i].taille_element;
     
   tri_bulle(tableau_taille,size);

   for(int i = 0; i < size; i++)
       for(int j = 0; j < size; j++)
       {
         if(tableau_taille[i] == tab[j].taille_element && tab[i].file_path != NULL)
         {
          print_element(tableau_taille[i], tab[j].file_path);
          break;
         }
       }
};
예제 #3
0
/*

Procédure créant les fichiers contenant le nombre moyen d'affectations
et de comparaisons pour toutes les tailles pour un algorithme. La procédure
prend le choix du tri en paramètre ainsi que les noms des fichiers à créer.

*/
void statistiques(char typeTri, char* fichierAff, char* fichierComp){
	
	int sommeComp, sommeAff, moyenneComp, moyenneAff, i, j, comparaisons, affectations, taille;

	int tableau[10000];
	
	FILE* fichier1 = fopen(fichierAff, "w");
	FILE* fichier2 = fopen(fichierComp, "w");
	
	for(i=0;i<10;i++){
		taille = valeur[i];
		sommeComp=0;
		sommeAff=0;
		for(j=0;j<N;j++){			
			init_tab(tableau, taille);
			comparaisons = 0;
			affectations = 0;
			switch (typeTri) {
			
				case 'S':
					tri_selection(tableau,taille, &comparaisons, &affectations);
					break;
					
				case 'I':
					tri_insertion(tableau,taille, &comparaisons, &affectations);
					break;
					
				case 'B':
					tri_bulle(tableau,taille, &comparaisons, &affectations);
					break;
					
				case 'D':
					q_sort(tableau, 0, taille-1, PIVOT_DEBUT, &comparaisons, &affectations);
					break;		
					
				case 'F':
					q_sort(tableau, 0, taille-1, PIVOT_FIN, &comparaisons, &affectations);
					break;
					
				case 'M':
					q_sort(tableau, 0, taille-1, PIVOT_MEDIAN, &comparaisons, &affectations);
					break;
					
				case 'A':
					q_sort(tableau, 0, taille-1, PIVOT_RANDOM, &comparaisons, &affectations);
					break;	
			}

			
			sommeComp = sommeComp + comparaisons;
			sommeAff = sommeAff + affectations;
		}
		moyenneComp = sommeComp / N;
		moyenneAff = sommeAff / N;
		fprintf(fichier1, "%d %d\n", taille, moyenneAff);
		fprintf(fichier2, "%d %d\n", taille, moyenneComp);
	}
	fclose(fichier1);
	fclose(fichier2);
	printf("Enregistrement des statistiques terminé.\n");
}