fix
parent
2eb372a5d1
commit
8ad1feabdf
43
Main.java
43
Main.java
|
@ -35,13 +35,19 @@ public class Main
|
|||
printBaum(baum.getRight());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void codes(String text)
|
||||
{
|
||||
Node wurzel = Node.erstellen(Zählen.countEachLetter(text));
|
||||
HashMap<Character, String> codes = new HashMap<Character, String>();
|
||||
|
||||
if(wurzel.getLeft() == null && wurzel.getRight() == null)
|
||||
{
|
||||
codes.put(wurzel.getBuchstabe(), "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
generieren(codes,wurzel,"");
|
||||
}
|
||||
|
||||
for (var entry : codes.entrySet())
|
||||
{
|
||||
|
@ -89,25 +95,34 @@ public class Main
|
|||
Node current = baum;
|
||||
String decoded = "";
|
||||
|
||||
boolean hatNurEinBuchstabenart = current.getRight() == null && current.getLeft() == null;
|
||||
if(hatNurEinBuchstabenart)
|
||||
{
|
||||
for(int i=0;i<code.length();i++)
|
||||
{
|
||||
decoded += baum.getBuchstabe();
|
||||
}
|
||||
System.out.println(decoded);
|
||||
return decoded;
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(int i =0;i<code.length();i++)
|
||||
{
|
||||
printBaum(current);
|
||||
System.out.println();
|
||||
|
||||
if(code.charAt(i) == '1')
|
||||
{
|
||||
current= current.getRight();
|
||||
}
|
||||
if(code.charAt(i) == '0')
|
||||
{
|
||||
current = current.getLeft();
|
||||
}
|
||||
if(current.getRight() == null && current.getLeft() == null)
|
||||
{
|
||||
decoded += current.getBuchstabe();
|
||||
current = baum;
|
||||
}
|
||||
|
||||
if(code.charAt(i) == '1')
|
||||
{
|
||||
current= baum.getRight();
|
||||
}
|
||||
if(code.charAt(i) == '0')
|
||||
{
|
||||
current = baum.getLeft();
|
||||
}
|
||||
}
|
||||
System.out.println(decoded);
|
||||
return decoded;
|
||||
|
|
Loading…
Reference in New Issue