1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <stdio.h>
void CourtChemin(int graphe[][1], int n, int depart,
int
arrive){
int i;
int j;
int k;
int l;
int chemin[n];
int solution[n];
int singleton=0;
int petit=n;
for(j=0; j<3*n; j++){
while(depart = ! arrive){
if(graphe[i][0]==depart){ //On regarde si le premier element du sous tableau est ce qu'on cherche. :D
chemin[singleton]=graphe[i][1];
singleton++; //Case suivante
depart=graphe[i][1]; //On cherche ce nouveau numero pour continuer le chemin.
graphe[i][0]=0; graphe[i][1]=0;} //On enlève ce chemin pour pas le trouver 2 fois. :aie:
if(graphe[i][1]==depart){ //Regardons le second element du sous tableau
chemin[singleton]=graphe[i][0];
singleton++; depart=graphe[i][0]; graphe[i][0]=0; graphe[i][1]=0;}
i++;
}
if(singleton<petit){petit=singleton; for(k=0; k<singleton;
k++){solution[k]=chemin[k];}} //Si le chemin trouvé est plus petit qu'un autre, nous remlaçons le précédent par celui-ci.
}
for(l=0; l<petit; l++){printf("%d ", solution[l]);} //Affichons
}
int main(){
int
graphe[7][2]={{1,2},{1,5},{2,5},{2,3},{3,4},{4,5},{4,6}};
CourtChemin(graphe[7][1], 7, 1, 6);
return 0;} |
Partager