Accueil     Soft. MacOSX     Soft. MacOS/PC     PHP     Python     ROMS GBA     TP d'info     DBZ-GT     Martingales     Galeries     Liens     @  

TP2 Génie Logiciel File

class File {
// declaration de la structure pour une file

// L'instanciation:
int []T; // Tableau
int indiceprochainout; // position du prochain element à sortir
int indiceprochainin; // position du prochain element à entrer
int nmax; // taille du tableau
int nbelem; // nombre d'element dans le tableau

// Constructor
File(int max) {
this.T=new int[max];
this.indiceprochainout=-1;
this.indiceprochainin=-1;
this.nmax=max;
this.nbelem=0;
}

boolean testvide() {
if (this.nbelem==0)
 return(true);
else
 return(false);
}

boolean testpleine() {
if (this.nbelem==this.nmax)
 return(true);
else
 return(false);
}

// Affichage d'une file
void affichagefile() {
int i;

if (this.testpleine())
 System.out.println("Votre pile est pleine !");
if (this.testvide())
 System.out.println("Votre pile est vide !");
else {
 i=this.indiceprochainout;
 do {
  System.out.println(this.T[i]);
  i++;
  if (i==this.nmax)
   i=0;
 } while(i!=this.indiceprochainin);
}
// pourquoi ne pas utiliser une boucle for ?
// parceque on a une file circulaire: arrivee en bout de tableau
// on recommence au debut , ce qui peut poser probleme aevc une boucle for ! ! !
}

boolean enfiler(int val) { // Ajout d'un element a la file.
// Renvoie true si tout est OK. Renvoie false si la pile est pleine.
if (this.indiceprochainin==-1) {
 this.indiceprochainin=0;
 this.indiceprochainout=0;
}

if (this.testpleine()) {
 System.out.println("Votre pile est pleine !");
 return(false);
}

this.T[indiceprochainin]=val;
this.indiceprochainin++;
if (indiceprochainin==this.nmax)
 indiceprochainin=0;
this.nbelem++;
return(true);
}

boolean defiler() {
// Suppression du premier element de la file
// Renvoie true si tout est OK. Renvoie false si la pile est vide.
if (this.testvide()) {
System.out.println("votre pile est vide");
return(false);
}

// Facultatif: on affiche la valeur que l'on va supprimer
System.out.println(this.T[indiceprochainout]);

this.indiceprochainout++;
if (indiceprochainout==this.nmax)
 indiceprochainout=0;
this.nbelem--;
return(true);
}
// ©2002 All Rights Reserved to Didier STRAUS www.Software-DS.com
}
 




Haut de la page - Page précédente - Page générée en 0.00594 sec.
Recherche personnalisée
 

1843943 visiteurs.   ©2001-2023 All Rights Reserved to Software-DS.com
Made with a mac  
Confidentialité