int main(int argc, char *argv[]) { file * f1 = creer_file(); printf("Création file 1\n"); afficher_file(f1); enfiler(f1, 50); enfiler(f1, 25); enfiler(f1, 2); enfiler(f1, 7); printf("Affichage file 1\n"); afficher_file(f1); printf("Défile file 1\n"); defiler(f1); afficher_file(f1); enfiler(f1, 7); printf("Enfile file 1\n"); afficher_file(f1); file * f2 = creer_file(); enfiler(f2, 3); enfiler(f2, 4); enfiler(f2, 5); printf("Création file 2\n"); afficher_file(f2); printf("Concaténation file 1 et 2\n"); concatener_files(f1, f2); afficher_file(f1); defiler(f1); defiler(f1); defiler(f1); defiler(f1); defiler(f1); defiler(f1); printf("Défiler file 1\n"); afficher_file(f1); printf("File 1 est vide : "); printf("%d\n", file_estVide(f2)); destruction(f2); destruction(f1); return 0; }
int bicolore(graphe g){ char* coule = (char*)calloc(g.nbsom,sizeof(char*)); file* liste = creer_file(); int ori, nbSommet=0,courant,nbS=g.nbsom,i,j; ori =0; for(i=0;i<nbS;i++){ coule[i]='N'; } enfiler(liste,ori); nbSommet++; coule[ori] ='B'; while(nbSommet<nbS){ while(!(file_estVide(liste))){ courant = defiler(liste); printf("Sommet %d, couleur : %c\n", courant, coule[courant]); for(i=0;i<nbS;i++){ if(g.matrice[courant][i]==1){ if(coule[i]!=coule[courant]){ if(coule[i]=='N'){ if(coule[courant]=='B'){ coule[i]='J'; }else{ coule[i]='B'; } enfiler(liste,i); nbSommet++; } }else{ return 0; } } } coule[courant]=2; } if(nbSommet!=nbS){ while(coule[j]!=0){ j++; } enfiler(liste,j); nbSommet++; coule[j]='B'; } } free(coule); free(liste); return 1; }
int pLargeur(graphe g){ int nbS=g.nbsom, i,ori=0, nbSommet, courant, nscc, booleen =1, ncc=0,j=0; file* liste = creer_file(); int* coule= (int*)calloc(nbS,sizeof(int*)); ori =0; enfiler(liste,ori); nbSommet = 0; nbSommet++; coule[ori] =1; while(nbSommet<nbS){ ncc++; nscc=0; while(!(file_estVide(liste))){ courant = defiler(liste); printf("Sommet %d\n", courant); for(i=0;i<nbS;i++){ if(g.matrice[courant][i]==1){ if(coule[i]==0){ coule[i]=1; enfiler(liste,i); nbSommet++; } } } coule[courant]=2; nscc++; } printf("La %deme composante connexe contient %d sommet(s). Nous avons actuellement %d/%d sommets\n",ncc, nscc, nbSommet,nbS); if(nscc != nbS){ booleen = 0; if(nbSommet!=nbS){ while(coule[j]!=0){ j++; } enfiler(liste,j); nbSommet++; } if(nbS == nbSommet){ printf("La %deme composante connexe contient %d sommet(s). Nous avons actuellement %d/%d sommets\n",ncc+1, 1, nbSommet,nbS); } } } free(coule); free(liste); return booleen; }
/* Affiche l'arbre en largeur */ void parcours_largeur(NOEUD * rac) { file * f = creer_file(); enfiler(f, rac); NOEUD * p; while (! file_estVide(f)) { p = defiler(f); printf("%d ", p->valeur); if (p->gauche) enfiler(f, p->gauche); if (p->droit) enfiler(f, p->droit); } printf("\n"); }