Bonjour a tous et merci de votre attention

Voila j'explique rapidement, je réaliste un projet qui consiste a créer un arbre dynamiquement selon le codage d'huffman

j'ai donc au préalable creer un type Liste et Arbre (sans méthode car nous n'avons pas le droit d'utiliser d'objet), la creation de la liste d'arbre contenant les noeuds avec les caractère et leurs nombre d’occurrence se passe bien, le tri également et la construction de petit arbre aussi, mais pour des longues comme pour cette exemple "this is an example of a Huffman tree"



quand j'affiche mon arbre je "perds" les noeuds après le 4ème niveau, ici il s'arrête donc au niveau e4 N4 a4 N4 N4 N4 N5 ' '7 (N désigne un noeud)

j'ai tester différente façon de le creer mais sans résultat, j'ai éventuellement une idée sur le fait que ça vienne d'un problème de gestion de mémoire mais je ne suis pas du tout qualifié sur ce sujet :/

Voici mon code (le code entre commentaire sert uniquement a des affiches pour faire des test)

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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
 
import java.util.Scanner;
public class Projet_huffman {
 
 
public static class Arbre
{
	public char c;
	public int occ; 
	public Arbre fG;
	public Arbre fD;
}
 
public static class Liste
{
	public Arbre A;
	public Liste suivant;
}
 
public static int comptechar(char c, String s)
{
	int occ=0, i;
	String part1, part2;
	for (i=0;i<s.length();i=i+1)
	{
		if (s.charAt(i)==c) 
		{
			occ=occ+1;
		}
	}
	return occ;
}
 
public static boolean check_char(char a, Liste l)
{
	if (l.A.c==a)
	{
		return true;
	}
	else
	{
		if (l.suivant!=null)
		{
			return check_char(a, l.suivant);
		}
		else
		{
			return false;
		}		
	}
}
 
public static Liste insere_queue(Liste l, int occa, char a)
{
	Liste l2=new Liste();
	Liste debutl=l;
	modiflA(l2, occa, a);
	while (l.suivant!=null)
	{
		l=l.suivant;
	}
	l.suivant=l2;
	return debutl;
}
 
public static Liste insere_N(Liste l, int occa, char a, Arbre A1, Arbre A2)
{
	Liste l2=new Liste();
	Liste debutl=l;
	modiflN(l2, occa, a, A1, A2);
	while (l.suivant!=null)
	{
		l=l.suivant;
	}
	l.suivant=l2;
	return debutl;
}
 
public static void modiflA(Liste l, int occ2, char c2)
{
	Arbre B = new Arbre ();
	B.c=c2;
	B.occ=occ2;
	l.A=B;
}
 
public static void modiflN(Liste l, int occ2, char c2, Arbre A1, Arbre A2)
{
	Arbre B = new Arbre ();
	B.c=c2;
	B.occ=occ2;
	B.fG=A1;
	B.fD=A2;
	l.A=B;
}
 
public static Liste trier(Liste L)
{
	Liste debutL=L;
	Arbre x=new Arbre ();
	if (L.suivant==null)
	{
		return L;
	}
	while (L.suivant!=null)
	{
		if (L.A.occ>L.suivant.A.occ)
		{
			x=L.A;
			modiflA(L, L.suivant.A.occ, L.suivant.A.c);
			modiflA(L.suivant, x.occ, x.c);
		}
		L=L.suivant;
	}
	if (check_trier(debutL)==false)
	{
		return trier(debutL);
	}
	return debutL;
}
 
public static boolean check_trier(Liste L)
{
	while (L.suivant!=null)
	{
		if (L.A.occ>L.suivant.A.occ)
		{
			return false;
		}
		L=L.suivant;
	}
return true;
}
 
public static Liste creer_arbre(Liste L)
{
	int occN;
	char N='N';
	while (L.suivant!=null)
	{
	occN=L.A.occ+L.suivant.A.occ;
	L=insere_N(L, occN, N, L.A, L.suivant.A);
	L=trier(L.suivant.suivant);
 
	/*  System.out.println("a la fin de chaque tour de creer arbre");
	Liste Ltest=L;
	while (Ltest.suivant!=null)
	{
		System.out.println(Ltest.A.c+" "+Ltest.A.occ);
		Ltest=Ltest.suivant;
	}
	System.out.println(Ltest.A.c+" "+Ltest.A.occ);
 
	System.out.println("et on affiche l'arbre");
	affiche_arbre(L.A);  */
	}
return L;
}
 
public static void affiche_arbre(Arbre A)
{
	if (A.fG!=null && A.fD!=null)
	{	
		if (A.fG==null && A.fD!=null)
		{
			System.out.println(A.c+" "+A.occ);
			affiche_arbre(A.fD);
		}
		else
		{
			if (A.fD==null && A.fG!=null)
			{
			System.out.println(A.c+" "+A.occ);
			affiche_arbre(A.fG);
			}
			else
			{
			System.out.println(A.c+" "+A.occ);
			affiche_arbre(A.fG);
			affiche_arbre(A.fD);
			}
		}
	}
	else
	{
	System.out.println(A.c+" "+A.occ);
	}
}
 
public static void main(String[] args)
{
	String phrase="";
	Liste L = new Liste ();
	int longueur, occa, i=1;
	char a;
	while( phrase.equals(""))
	{
		System.out.println("Entrez votre phrase.");
		phrase = (new Scanner(System.in)).nextLine();
	}
	longueur = phrase.length();
	a = phrase.charAt(0);           //on remplit la 1ère cellule de la liste pour pouvoir executer les tests check_char dans la boucle sinon erreur NullPointerException les cellules ne sont pas encore crées
	occa = comptechar(a, phrase);
	modiflA(L, occa, a);
	while (i<longueur)
	{
		a = phrase.charAt(i);
		if (check_char(a, L)==false)
		{
			occa = comptechar(a, phrase);
			L=insere_queue(L, occa, a);
		}
		i=i+1;
	}
 
	/*  System.out.println("liste : avant creer arbre et avant tri");
	Liste Ltest=L;
	while (Ltest.suivant!=null)
	{
		System.out.println(Ltest.A.c+" "+Ltest.A.occ);
		Ltest=Ltest.suivant;
	}
	System.out.println(Ltest.A.c+" "+Ltest.A.occ);  */ 
 
	L=trier(L);
 
	/*  System.out.println("liste : avant creer arbre et apres tri");
	Ltest=L;
	while (Ltest.suivant!=null)
	{
		System.out.println(Ltest.A.c+" "+Ltest.A.occ);
		Ltest=Ltest.suivant;
	}
	System.out.println(Ltest.A.c+" "+Ltest.A.occ);  */
 
	L=creer_arbre(L);
 
	/* System.out.println("liste : apres creation");
	Ltest=L;
	while (Ltest.suivant!=null)
	{
		System.out.println(Ltest.A.c+" "+Ltest.A.occ);
		Ltest=Ltest.suivant;
	}
	System.out.println(Ltest.A.c+" "+Ltest.A.occ);
 
	System.out.println("et on affiche l'arbre");
	affiche_arbre(L.A);  */
 
}
}
Voila, merci d'avance cordialement Seishi