Bonsoir tous le monde;
Je dois réaliser un programme qui implémente une file avec une liste chainée, j'ai écrit un petit code mais malheureusement ça me donne un résultat non désiré, je demande votre aide SVP.
voila le code de mon programme:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <stdlib.h>
#define taille 50
using namespace std;
 
typedef struct noeud
{
  char nom;
  char succ [taille];
  char pred [taille];
  int nbrsucc;
  int nbrpred;
  struct noeud* suivant;
};
 
typedef struct File{
  noeud *debut;
  noeud *fin;
  int size;
} ;
 
void initialiser (File &suite){
  suite.debut = NULL;
  suite.fin = NULL;
  suite.size = 0;
} 
 
noeud* initialisation(){
       return NULL;
       }
 
bool estVide(File &suite){
     return (suite.debut == NULL || suite.fin == NULL);
     }
 
void enfiler (File &suite,noeud* courant,noeud graphe ){
  noeud* nouveau_element;
  nouveau_element=&graphe;
  cout<<nouveau_element->nom<<endl;
  if(courant == NULL){
    if(suite.size == 0)
    suite.fin = nouveau_element;
    nouveau_element->suivant = suite.debut;
    suite.debut = nouveau_element;
  }
  else {
    if(courant->suivant == NULL)
      suite.fin = nouveau_element;
    nouveau_element->suivant = courant->suivant;
    courant->suivant = nouveau_element;
     } 
  suite.size++;
 
}   
 
/* affichage de la file */
void affiche(File &suite){
  noeud* courant;
  int i,j;
  courant = suite.debut;
  while(courant->suivant != NULL)
  {
    cout<<"le nom du noeud: "<<courant->nom<<endl; 
             cout<<"Les successeurs de "<<courant->nom<<" sont:    ";
             for(i=0;i<courant->nbrsucc;i++)
                 cout<<courant->succ[i]<<"  ;";
            cout<<endl;
            cout<<"Les predeccesseurs de: "<<courant->nom<<" sont:     ";    
             for(i=0;i<courant->nbrpred;i++)
                 cout<<courant->pred[i]<<"  ;";
            cout<<endl;
            courant = courant->suivant;
  }
}
 
int main(){
    int choix,rep1,rep2,rep3;
    noeud graphe;
    File suite;
    char noun;
    initialiser(suite); 
    do{   
          cout<<endl<<"-- Menu --"<<endl;
          cout<<"1 - Creer un graphe "<<endl;  
          cout<<"2 - Afficher le graphe "<<endl;
          cout<<"3 - Decomposer le graphe en niveaux "<<endl;
       /* cout<<"4 - affichier la nouvelle struture du graphe "<<endl;*/
          cout<<"0 - Quitter "<<endl;
          cout<<"Entrer votre choix "<<endl;
          cin>>choix;
 
          switch(choix){
                case 1: { 
                           while( rep1 != 0){
                             cout<<"Pour entrer un noeud veuillez tapez 1 sinon tapez 0:"<<endl;
                             cin>>rep1;
                             if(rep1==1){ 
                               cout<<"Entrez le nom du noeud:"<<endl;
                               cin>>noun;
                               graphe.nom=noun;
                               graphe.nbrsucc=0;
                               graphe.nbrpred=0;
                               while( rep2 != 0){
                                    cout<<"Pour entrer un successeur de "<<graphe.nom<<" veuillez tapez 1 sinon tapez 0:"<<endl;
                                    cin>>rep2;
                                    if(rep2==1){
                                         graphe.nbrsucc++;       
                                         cout<<"Entrez le nom du successeur:"<<endl;
                                         cin>>graphe.succ[graphe.nbrsucc-1];                         
                                              }
                                     }  
                               while(rep3 !=0){
                                    cout<<"Pour entrer un predeccesseur de "<<graphe.nom<<" veuillez tapez 1 sinon tapez 0:"<<endl;
                                    cin>>rep3;
                                    if(rep3 ==1){
                                        graphe.nbrpred++;
                                        cout<<"Entrez le nom du predecesseur:"<<endl;
                                        cin>>graphe.pred[graphe.nbrpred-1];
                                               } 
                                  }   
                                  }
 
                          enfiler (suite,suite.fin,graphe);
                      }   
                                }
                                break;
 
                        case 2: {if (estVide(suite))
                                    cout<<"Le graphe est vide "<<endl;
                                else
                                    affiche(suite);
                                }
                                break;
                        case 3: {if (estVide(suite))
                                 cout<<"Le graphe est vide "<<endl;
                                 else{
                                      ;
                                     }
                                }   
                        }
       }while(choix!=0);      
system("pause");
 return 0;
}