/*
* Parcours en parcours_en_profondeur
*/
void parcours_en_profondeur(tGraphe graphe, tNumeroSommet sommet, char *outfile){
  tTabCouleurs couleurs;
  tPileSommets pile;
  tNumeroSommet xSommet;

  int i[MAX_SOMMETS];
  int nSommet = grapheNbSommets(graphe);
  int entrer;

  /* On Initialise les couleurs et l'indice i*/
  init_parcours(graphe, couleurs, i, nSommet);
  /* On dépile tout en affichant */
  pile = pileSommetsAlloue();

  /* On colorie le promier sommet en vert et on l'enpile */
  couleurs[sommet] = VERT;
  pileSommetsEmpile(pile, sommet);

  while (!pileSommetsEstVide(pile)) {
    graphe_visu_color(graphe, couleurs, outfile);
    xSommet = pileSommetsTete(pile);
    traitement_pile(pile, xSommet, i, graphe, couleurs);
    scanf("%d", &entrer);
  }
  graphe_visu_color(graphe, couleurs, outfile);
  pileSommetsLibere(pile);
  printf("resultat du parcours en profondeur: ---------------------------------------\n");
  print_i(graphe, i, nSommet);
}
Example #2
0
tNumeroSommet pileSommetsDepile(tPileSommets pile) {
  tNumeroSommet res;
  if (pileSommetsEstVide(pile))
    halt("Ne peut depiler d'une pile vide");
  res = pile->tab[pile->tete-1];
  (pile->tete)--;
  
  return res;
}
Example #3
0
void parcour_Profondeur(tGraphe g,char* sommet){
  
  
  int i,nbVoisin;
  
  tNumeroSommet sommetDepart,suivant,x;
  tNomSommet nom;
 tTabCouleurs coul;
  tPileSommets file;
  
  
  file= pileSommetsAlloue();
  sommetDepart=grapheChercheSommetParNom(g,sommet);
  
  // n opérations pour la boucle
  for (i=0;i<grapheNbSommets(g);i++)
    coul[i]=1;
  coul[sommetDepart] = 2;


  printf("\n\n\n\ndebut de l'empilade\n");
  pileSommetsEmpile(file,sommetDepart);
  while(!pileSommetsEstVide(file))
    {
      x=pileSommetsDepile(file);
      nbVoisin=grapheNbVoisinsSommet(g,x);
   
      for(i=0;i<nbVoisin;i++)
	{
	  suivant=grapheVoisinSommetNumero(g,x,i);
	  if(coul[suivant]==1)
	    {
	      coul[suivant]=2;
	      pileSommetsEmpile(file,suivant);
	      
	    }
	  coul[x]=0;
	     grapheRecupNomSommet(g,x,nom);
      printf("%s est trouvé\n",nom);
	}
    }  
}
Example #4
0
tNumeroSommet pileSommetsTete(tPileSommets pile) {
  if (pileSommetsEstVide(pile))
    halt("Ne peut renvoyer la tete d'une pile vide");
  return pile->tab[pile->tete-1];
}
Example #5
0
int solutionLab(tGraphe graphe, tNomSommet entree, tNomSommet sortie, tTabCouleurs tabCouleurs)
{

  int i, pasVoisinBleu;
  tNumeroSommet numE, numS, x, y, varChemin;
  tNomSommet nomVarChemin, nom1,nom2;
  tPileSommets pile, pileChemin;

  pile = pileSommetsAlloue();
  pileChemin = pileSommetsAlloue();
  pasVoisinBleu = 1 == 1;
  for(i = 0; i < grapheNbSommets(graphe); i++)
  {

    tabCouleurs[i] = BLEU;
  }
  numE = grapheChercheSommetParNom(graphe, entree);
  numS = grapheChercheSommetParNom(graphe, sortie);
  tabCouleurs[numE] = VERT;
  pileSommetsEmpile(pile, numE);
  while(!pileSommetsEstVide(pile)&& pileSommetsTete(pile) != numS)
  {

    x = pileSommetsTete(pile);
    pasVoisinBleu = 1 == 1;
    for(i = 0; i < grapheNbVoisinsSommet(graphe, x);i++)
    {
      y = grapheVoisinSommetNumero(graphe, x, i);
      if(tabCouleurs[y] == BLEU)
      {

        tabCouleurs[y] = VERT;
        pileSommetsEmpile(pile, y);
        pasVoisinBleu = pasVoisinBleu && 0 == 1;
      }
    }
    if(pasVoisinBleu)
    {

      x = pileSommetsDepile(pile);
      tabCouleurs[x] = ROUGE;
    }
  }
  if(!pileSommetsEstVide(pile)&& pileSommetsTete(pile) == numS)
  {

    while(!pileSommetsEstVide(pile))
    {

      varChemin = pileSommetsDepile(pile);
      pileSommetsEmpile(pileChemin, varChemin);

      if(!pileSommetsEstVide(pile))
      {
        while(!estVoisin(graphe, pileSommetsTete(pile), varChemin))
        {

          pileSommetsDepile(pile);
        }
      }
    }

    while(!pileSommetsEstVide(pileChemin))
    {
      grapheRecupNomSommet(graphe, pileSommetsDepile(pileChemin), nomVarChemin);
      printf("%s\n", nomVarChemin );
    }
    return 0 == 0;
  }
  return 0 == 1;
}