kommentare
parent
a61b239846
commit
ac1fa09229
12
Main.java
12
Main.java
|
@ -8,7 +8,6 @@ import java.nio.file.Path;
|
|||
public class Main
|
||||
{
|
||||
public static byte[] nullCharBytes = {(byte)0xFF,(byte)0xFF};
|
||||
//public static String nullCharBytesString = "1111111111111111";
|
||||
public static void test(String text)
|
||||
{
|
||||
Map<Character, Integer> zahlen = Zählen.countEachLetter(text);
|
||||
|
@ -48,7 +47,7 @@ public class Main
|
|||
Map<Character, Integer> zahlen = Zählen.countEachLetter("aaaabbc");
|
||||
Node wurzel = Node.erstellen(zahlen);
|
||||
printBaum(wurzel);
|
||||
//byteString_to_baum(baum_to_byteString(wurzel));
|
||||
|
||||
HashMap<Character, String> codes = new HashMap<Character, String>();
|
||||
|
||||
if(wurzel.getLeft() == null && wurzel.getRight() == null)
|
||||
|
@ -71,11 +70,9 @@ public class Main
|
|||
public static void test3()
|
||||
{
|
||||
System.out.println(decodierungInlkBaum(codierungInklBaum("aaaabbc")));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void printBaum(Node baum)
|
||||
public static void printBaum(Node baum) //gibt den Baum rekurssiv in pre-order aus
|
||||
{
|
||||
if(baum == null)return;
|
||||
System.out.println("Buchstabe: " + baum.getBuchstabe() + ", Anzahl: " + baum.getAnzahl());
|
||||
|
@ -83,7 +80,7 @@ public class Main
|
|||
printBaum(baum.getRight());
|
||||
}
|
||||
|
||||
public static void codes(String text)
|
||||
public static void codes(String text) //erstellt die codes für jeden einzelnen Buchstaben
|
||||
{
|
||||
Node wurzel = Node.erstellen(Zählen.countEachLetter(text));
|
||||
HashMap<Character, String> codes = new HashMap<Character, String>();
|
||||
|
@ -103,6 +100,8 @@ public class Main
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//methode zum generieren der codes für jeden einzelnen Buchstaben
|
||||
public static void generieren(HashMap<Character, String> codes, Node node, String code)
|
||||
{
|
||||
if(node == null)return;
|
||||
|
@ -117,6 +116,7 @@ public class Main
|
|||
generieren(codes, node.getRight(), code + "1");
|
||||
}
|
||||
|
||||
//generiert die Huffman-Codierung
|
||||
public static String codierung(String text, Node wurzel)
|
||||
{
|
||||
HashMap<Character, String> codes = new HashMap<Character, String>();
|
||||
|
|
12
Node.java
12
Node.java
|
@ -14,12 +14,14 @@ public class Node
|
|||
{
|
||||
}
|
||||
|
||||
public Node(Node left, Node right)
|
||||
public Node(Node left, Node right) //constructor für node
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
|
||||
//set und get methoden für verschiedenes
|
||||
public Node getLeft(){return left;}
|
||||
|
||||
public void setLeft(Node left){this.left = left;}
|
||||
|
@ -63,22 +65,22 @@ public class Node
|
|||
return nodes.poll();
|
||||
}
|
||||
|
||||
public void add(Node node)
|
||||
public void add(Node node) //fügt ein Kind an die freie Stelle von dem baum hin wenn möglich
|
||||
{
|
||||
if(left == null)
|
||||
if(left == null) //als erstes überprüft es die linke Seite
|
||||
{
|
||||
left= node;
|
||||
return;
|
||||
}
|
||||
|
||||
if(right == null)
|
||||
if(right == null) //danach überprüft es die linke Seite
|
||||
{
|
||||
right= node;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hatPlatzKinder()
|
||||
public boolean hatPlatzKinder() //überprüft ob der baum schon "voll" ist
|
||||
{
|
||||
return left==null || right==null;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import java.util.Map;
|
|||
|
||||
public class Zählen
|
||||
{
|
||||
public static Map<Character, Integer> countEachLetter(String input)
|
||||
public static Map<Character, Integer> countEachLetter(String input) //erstellt eine Map die jeden character zählt
|
||||
{
|
||||
// Konvertiere den String in ein char-Array
|
||||
char[] characters = input.toCharArray();
|
||||
|
@ -21,7 +21,7 @@ public class Zählen
|
|||
return letterCountMap ;
|
||||
}
|
||||
|
||||
public static void printZahl (Map<Character, Integer> letterCountMap)
|
||||
public static void printZahl (Map<Character, Integer> letterCountMap) //printed allle characters mit deren anzahl
|
||||
{
|
||||
for (Map.Entry<Character, Integer> entry : letterCountMap.entrySet())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue