Ejemplo n.º 1
0
int	check(char **tab, char **piece, int x, int y)
{
  int	hauteur_p;
  int	hauteur_t;
  int	i;
  int	j;
 
  hauteur_p = hauteur(piece);
  hauteur_t = hauteur(tab); 
  i = 0;
  if (((x + strlen(*piece)) > strlen(*tab)) || ((y + hauteur_p) > hauteur_t))
      return (0);
  while (piece[i] != NULL)
    {
      j = 0;
      while (piece[i][j] != '\0')
	{
	  if (piece[i][j] != '.' && tab[y + i][x + j] != '.')
	    return (0);
	  j = j + 1;
	}
      i = i + 1;
    }
  return (1);
}
Ejemplo n.º 2
0
// Fonction de rotation à gauche (pour équilibrer les arbres)
ABR *rotG(ABR *abr) {
  ABR *tmp=abr->d;
  abr->d=tmp->g;
  tmp->g=abr;
  abr->h=1+max(hauteur(abr->g), hauteur(abr->d));
  tmp->h=1+max(hauteur(tmp->g), hauteur(tmp->d));
  return tmp;
}
Ejemplo n.º 3
0
int hauteur(const Abin a)
{
	int Maximum(const int a, const int b);

	if (estVide(a))
	{
		return 0;
	}
	return 1 + Maximum(hauteur(gauche(a)), hauteur(droite(a)));
}
Ejemplo n.º 4
0
int hauteur(sabr *a)
	{
		if (a==NULL)
		{ return (-1); }
		else
		{
			if (hauteur(a -> g) > hauteur(a -> d))	
			{ return hauteur(a -> g) + 1; }
			else
			{ return hauteur(a -> d) + 1; }
		}
	}
Ejemplo n.º 5
0
int hauteur (Arbre arbre){

    int res=0;
    if(arbre == NULL || is_feuille(arbre) )
    {
        res=0;
    }
    else
    {
        int hauteur1 = max(hauteur(arbre->fils[NO]),hauteur(arbre->fils[SE]));
        int hauteur2 = max(hauteur(arbre->fils[NO]),hauteur(arbre->fils[NE]));
        res=1+max(hauteur1,hauteur2);
    }
    return res;
}
Ejemplo n.º 6
0
// OK
int hauteur(Arbre* racine)
{
	if(racine==NULL)
	{
		return 0;
	}
    //Compte le nombre maximum de sous arbre gauche
    int nbNoeudGauche = hauteur(racine->gauche);
    
    //Compte le nombre maximum de sous arbre droit
    int nbNoeudDroit = hauteur(racine->droit);
    
    //Retourne le maximum entre les deux sous arbre
    return max(nbNoeudDroit,nbNoeudGauche)+1;
}
Ejemplo n.º 7
0
 void Fenetre::miseAJour() { // méthode probablement inutile laissée pour compatibilité 
    if (!existe) return;
    gdk_draw_drawable (fenetre->window,
		     fenetre->style->fg_gc[GTK_WIDGET_STATE (fenetre)],
		     dessin, 0, 0, 0, 0, largeur(), hauteur());
   traiteEvenements();
 }
Ejemplo n.º 8
0
bool FenetreDessin::estDansLaFenetre(int x, int y) const
{
    if(x>0 && x<=this->largeur() && y>0 && y<=hauteur())
        return true;
    else
        return false;
}
Ejemplo n.º 9
0
//Donner la hauteur pour un noeud donné
int hauteur (arbre a, int elemt)
{
	int h;

	if (a == NULL) 
		return -1;
	if(a->val == elemt)
		return 0 ;
	h=1+hauteur(a->gauche,elemt);
	if (h==0)
	{
		h=1+hauteur(a->droit,elemt);
		if (h==0)
			return -1;
		else 
			return h;
	}
	return h;
}
Ejemplo n.º 10
0
 void Fenetre::effacer() { // remplit tout le bitmap avec la couleur de fond
   if (existe) {
      gdk_gc_set_rgb_fg_color(fenetre->style->bg_gc[GTK_STATE_NORMAL],&fond);
      gdk_draw_rectangle (dessin,
    		 /*fenetre->style->white_gc*/ fenetre->style->bg_gc[GTK_STATE_NORMAL],
    		 TRUE, 0, 0, largeur(), hauteur());
      gtk_widget_queue_draw(fenetre);
      traiteEvenements();
      }
}
Ejemplo n.º 11
0
void affiche_ligne(P4 jeu, Nat l) {
    int i;
    printf("\t");
    for (i=0; i<7; ++i) {
        if (hauteur(jeu.tPile[i]) < l) printf ("|   ");
        else {
            if (kieme(jeu.tPile[i], l) == faux) printf ("| X ");
            else printf ("| O ");
        }
    }
    printf("|\n");
    return;
}
Ejemplo n.º 12
0
int hauteur(Arbre A){
  if(A == NULL)
    return -1;
  else{
    int i;
    int tmp;
    int max = -1;
    for(i = 0; i < FILS_MAX; i++){
      tmp = hauteur(A -> fils[i]);
      if(tmp > max)
        max = tmp;
    }
    return max + 1;
  }
}
Ejemplo n.º 13
0
// Fonction d'équilibre
// Teste si il y a besoin d'équilibrer, puis applique la bonne rotation
ABRe *equilibre(ABRe *abr) {
  if(!abr)
    return abr;

  int d=hauteur(abr->g)-hauteur(abr->d);
  if(abs(d)<=1)
    return abr;

  if(d==2) {
    if(hauteur(abr->g->g)>=hauteur(abr->g->d))
      return rotD(abr);
    return rotGD(abr);
  }

  if(hauteur(abr->d->d)>=hauteur(abr->d->g))
    return rotG(abr);
  return rotDG(abr);
}
Ejemplo n.º 14
0
int main()
{
	arbre a,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7,tmp8,tmp9;

	tmp1 = (arbre)malloc(sizeof(struct noeud));
	tmp1->val = 1;
	tmp1->gauche = NULL;
	tmp1->droit = NULL;

	tmp2 = (arbre)malloc(sizeof(struct noeud));
	tmp2->val = 3;
	tmp2->gauche = NULL;
	tmp2->droit = NULL;

	tmp3 = (arbre)malloc(sizeof(struct noeud));
	tmp3->val = 7;
	tmp3->gauche = NULL;
	tmp3->droit = NULL;

	tmp4 = (arbre)malloc(sizeof(struct noeud));
	tmp4->val = 9;
	tmp4->gauche = NULL;
	tmp4->droit = NULL;

	tmp5 = (arbre)malloc(sizeof(struct noeud));
	tmp5->val = 2;
	tmp5->gauche = tmp1;
	tmp5->droit = tmp2;

	tmp6 = (arbre)malloc(sizeof(struct noeud));
	tmp6->val = 6;
	tmp6->gauche = NULL;
	tmp6->droit = tmp3;

	tmp7 = (arbre)malloc(sizeof(struct noeud));
	tmp7->val = 10;
	tmp7->gauche = tmp4;
	tmp7->droit = NULL;

	tmp8 = (arbre)malloc(sizeof(struct noeud));
	tmp8->val = 4;
	tmp8->gauche = tmp5;
	tmp8->droit = NULL;

	tmp9 = (arbre)malloc(sizeof(struct noeud));
	tmp9->val = 8;
	tmp9->gauche = tmp6;
	tmp9->droit = tmp7;

	a = (arbre)malloc(sizeof(struct noeud));
	a->val = 5;
	a->gauche = tmp8;
	a->droit = tmp9;


	printf("La hauteur de 10 est %d\n",hauteur(a,10));
	printf("Taille de l'arbre a = %d\n",taille(a));
	
	printf("Affiche prefixe : ");
	affiche_prefixe (a);
	inserer (&a,1);
	printf("\n");
	printf("Affiche infixe  : ");
	affiche_infixe (a);
	inserer (&a,11);
	printf("\n");
	printf("Affiche suffixe : ");
	affiche_suffixe (a);
	printf("\n");

	printf ("Recherche de 2 = %d\n",recherche(a,2));
	printf ("Recherche de 12 = %d\n",recherche(a,12));
	printf ("Recherche de 2 = %d\n",recherche(a,5));
	printf ("Recherche de 12 = %d\n",recherche(a,0));
	
	detruit(&a);

	printf("Affiche suffixe : ");
	affiche_suffixe (a);
	printf("\n");
	
	return 0;

}
Ejemplo n.º 15
0
int rayon(Arbre A){
  return TAILLE_FEN / (hauteur(A)*2);
}
Ejemplo n.º 16
0
int main(int argc, char ** argv){
  struct timeval start, end;
  Liste * fichiers = fichiers_reguliers(SHAKESPEARE_DIR);
  Liste * mots;
  char * fichier;
  TrieHybride * t = NULL;
  int i,fd,fd2,arg_fusion,res;
  double res_d;
  char buff[128];
  pthread_t tid[NB_THREADS];
  pthread_attr_t attr; 
  briandais_t * br;

  /****************************************************************************
                      BENCHMARK INSERTION NON MULTITHREADE
  ****************************************************************************/
  printf("Insertion de toutes les pieces de Shakespeare \t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  while((fichier=supprimer_debut(fichiers))){
    t=lire_fichier_th(fichier,t);
    free(fichier);
  }
  temps(&end);
  afficher_res(start,end);
  destroy_liste(fichiers);

  /****************************************************************************
                          SUPPRESSION MOTS HAMLET
  ****************************************************************************/
  printf("Suppression des mots de la piece \"Hamlet\" \t\t: En cours ...");  
  fflush(stdout);

  fd=ouvrir_fichier(SHAKESPEARE_DIR"hamlet.txt");
  if(fd<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  temps(&start);
  while(mot_suivant(fd,buff)>0){
    t=supprimer(t,buff);
  }
  temps(&end);
  afficher_res(start,end);

  if(close(fd)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  }

  /****************************************************************************
                         RECHERCHE ALL'S WELL & HAMLET
  ****************************************************************************/
  printf("Recherche des mots de All's Well et Hamlet \t\t: En cours ...");  
  fflush(stdout);

  fd=ouvrir_fichier(SHAKESPEARE_DIR"hamlet.txt");
  if(fd<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  fd2=ouvrir_fichier(SHAKESPEARE_DIR"allswell.txt");
  if(fd2<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  temps(&start);
  while(mot_suivant(fd,buff)>0){
    recherche_trie_hybride(t,buff);
  } 
  while(mot_suivant(fd2,buff)>0){
    recherche_trie_hybride(t,buff);
  }
  temps(&end);

  afficher_res(start,end);
  if(close(fd)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  } 

  if(close(fd2)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  }

  /****************************************************************************
                        DESTRUCTION TRIE HYBRIDE
  ****************************************************************************/
  printf("Destruction du trie hybride \t\t\t\t: En cours ...");  
  fflush(stdout);

  temps(&start);
  free_trie_hybride(t);
  temps(&end);

  afficher_res(start,end);

  /****************************************************************************
                       CREATION SHAKESPEARE MULTITHREADE
  ****************************************************************************/
  fics=fichiers_reguliers(SHAKESPEARE_DIR);
  tries=creer_liste();
  sem_init(&sem,1,0);
  arg_fusion=fics->taille;  
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);

  printf("Insertion multithreade des oeuvres de Shakespeare\t: En cours ...");  
  fflush(stdout);


  temps(&start);
  pthread_mutex_lock(&mutex_fics);
  for(i=0;i<NB_THREADS-1;i++){
    if(pthread_create(&(tid[i]),&attr,creation_trie_thread,NULL)==-1){
      perror("pthread_create");
      exit(EXIT_FAILURE);
    }
  }
  
  if(pthread_create(&(tid[NB_THREADS-1]),&attr,fusion_thread,&arg_fusion)==-1){
    perror("pthread_create");
    exit(EXIT_FAILURE);
  }

  pthread_cond_wait(&cond,&mutex_fics);
  temps(&end);

  afficher_res(start,end);

  destroy_liste(fics);
  t=supprimer_debut(tries);
  destroy_liste(tries);

 /****************************************************************************
                                COMPTAGE MOTS
  ****************************************************************************/
  printf("Comptage des mots \t\t\t\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  res=comptage_mots(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                              POINTEURS VERS NULL
  ****************************************************************************/ 
  printf("Comptage des pointeurs vers NULL\t\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  res=comptage_nil(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                 CREATION ET DESTRUCTION DE LA LISTE DES MOTS
  ****************************************************************************/ 
  printf("Creation et destruction de la liste des mots\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  mots=liste_mots(t);
  while(mots->taille!=0){
    char * tmp=supprimer_debut(mots);
    free(tmp);
  }
  free(mots);
  temps(&end);
  afficher_res(start,end);

  /****************************************************************************
                                   HAUTEUR
  ****************************************************************************/
  printf("Calcul de la hauteur \t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=hauteur(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);


  /****************************************************************************
                                 EQUILIBRAGE
  ****************************************************************************/
  printf("Equilibrage du trie\t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  t=equilibrer(t);
  temps(&end);
  afficher_res(start,end);

  /****************************************************************************
                              RECALCUL HAUTEUR
  ****************************************************************************/
  printf("Recalcul de la hauteur \t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=hauteur(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                             PROFONDEUR MOYENNE
  ****************************************************************************/
  printf("Profondeur Moyenne\t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res_d=profondeur_moyenne(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %f\n",res_d);

  /****************************************************************************
                          CONVERSION VERS BRIANDAIS
  ****************************************************************************/
  printf("Conversion vers arbre de la briandais\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  br=conversion(t);
  temps(&end);
  afficher_res(start,end);
  destroy_briandais(&br);

  /****************************************************************************
                        INSERTION D'UN MOT INEXISTANT
  ****************************************************************************/
  printf("Insertion d'un mot inexistant(anticonstitutionnellement): En cours ...");
  fflush(stdout);
  temps(&start);
  t=ajouter_trie_hybride("anticonstitutionnellement",t);
  temps(&end);
  afficher_res(start,end);
 
 /****************************************************************************
                        INSERTION D'UN MOT INEXISTANT
  ****************************************************************************/
  printf("Usage memoire (en octets)\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=usage_memoire(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  free_trie_hybride(t);
  return EXIT_SUCCESS;
}