Probleme recréer un arbre binaire
minaurore
-
KX Messages postés 19031 Statut Modérateur -
KX Messages postés 19031 Statut Modérateur -
bonjour je dois recréer un arbre à partir de la racine.
j'ai un fichier txt:
(les 1 et 0 sont des bit et les lettres sont codé sur 8bits)
111110
0
0a11110k110B10Y0ü10-10Ò10z10)0ø10ö0'0d110c0f10÷110ÿ110C0ø10Î0K110!0ÿ0ô110o0t110ü10ì0ù110þ10b1110F10þ0q0û0I110p10H10ÿ110Ñ0]10ÿ111110"0&010J0ú10V0Õ0m0
les 1 represente un noeud interne et une feuille du caractere a mettre dans la feuille.
pour créer ce texte j'ai utilisé cette fonction:
/*
private void copierArbre1(Noeud x) {
if (x.estUneFeuille()) {
B1.write(false);
B1.write(x.getcharactere());
}
else{
B1.write(true);
copierArbre1(x.getNoeudGauche());
copierArbre1(x.getNoeudDroit());
}
}
public void copierArbre(Noeud x) throws FileNotFoundException, IOException {
PrintWriter out = new PrintWriter(copieArbre);
B1 = new ByteCopy(out);
copierArbre1(x);
B1.close();
}*/
Mais maintenant j'essaye de recréer mon arbre avec cette fonction:
.....
copieArbre=new File("copieArbre.txt");
R1 = new ByteRead(copieArbre);
Racine=monterArbre();
R1.close();
.....
public Noeud monterArbre() throws IOException {
boolean c = R1.readBoolean();
if (c) {
return new Noeud('\0', -1, monterArbre(), monterArbre());
}
else{
return new Noeud(R1.readChar(), -1, null, null);
}
}
mais en faisant une fonction pour afficher mon arbre je n'obtient plus du tout la meme chose. je ne vois pas ce qui ne va pas!!
( un Noeud(char,int,NoeudGauche,NoeudDroit))
fonction que j'utilise pour voir l'arbre en console:
public void afficheArbre(Noeud x){
if (x.estUneFeuille()){
System.out.print("0");
System.out.print(x.getcharactere());
}
else{
System.out.print("1");
afficheArbre(x.getNoeudGauche());
afficheArbre(x.getNoeudGauche());
}
}
(estUneFeuille si x.NoeudDroit et Gauche == null)
Merci du temps que vous pouvez m'accorder!
j'ai un fichier txt:
(les 1 et 0 sont des bit et les lettres sont codé sur 8bits)
111110
0
0a11110k110B10Y0ü10-10Ò10z10)0ø10ö0'0d110c0f10÷110ÿ110C0ø10Î0K110!0ÿ0ô110o0t110ü10ì0ù110þ10b1110F10þ0q0û0I110p10H10ÿ110Ñ0]10ÿ111110"0&010J0ú10V0Õ0m0
les 1 represente un noeud interne et une feuille du caractere a mettre dans la feuille.
pour créer ce texte j'ai utilisé cette fonction:
/*
private void copierArbre1(Noeud x) {
if (x.estUneFeuille()) {
B1.write(false);
B1.write(x.getcharactere());
}
else{
B1.write(true);
copierArbre1(x.getNoeudGauche());
copierArbre1(x.getNoeudDroit());
}
}
public void copierArbre(Noeud x) throws FileNotFoundException, IOException {
PrintWriter out = new PrintWriter(copieArbre);
B1 = new ByteCopy(out);
copierArbre1(x);
B1.close();
}*/
Mais maintenant j'essaye de recréer mon arbre avec cette fonction:
.....
copieArbre=new File("copieArbre.txt");
R1 = new ByteRead(copieArbre);
Racine=monterArbre();
R1.close();
.....
public Noeud monterArbre() throws IOException {
boolean c = R1.readBoolean();
if (c) {
return new Noeud('\0', -1, monterArbre(), monterArbre());
}
else{
return new Noeud(R1.readChar(), -1, null, null);
}
}
mais en faisant une fonction pour afficher mon arbre je n'obtient plus du tout la meme chose. je ne vois pas ce qui ne va pas!!
( un Noeud(char,int,NoeudGauche,NoeudDroit))
fonction que j'utilise pour voir l'arbre en console:
public void afficheArbre(Noeud x){
if (x.estUneFeuille()){
System.out.print("0");
System.out.print(x.getcharactere());
}
else{
System.out.print("1");
afficheArbre(x.getNoeudGauche());
afficheArbre(x.getNoeudGauche());
}
}
(estUneFeuille si x.NoeudDroit et Gauche == null)
Merci du temps que vous pouvez m'accorder!
A voir également:
- Probleme recréer un arbre binaire
- Binaire - Guide
- Arbre généalogique famille michelin - Télécharger - Généalogie
- Editeur binaire - Télécharger - Édition & Programmation
- Alphabet binaire - Forum Programmation
- Codage de caractère en binaire ✓ - Forum Programmation
Si tu as des bugs, donne ton code,et je regarderai, mais vu les codes que j'ai pu voir aujourd'hui et avant-hier j'aurai sûrement beaucoup de remarques donc expliques bien les problèmes que tu veux résoudre sinon je risque de te faire modifier ton code bien plus que nécessaire !