Professional Documents
Culture Documents
Clase nodo:
package huffmanexe;
public class Node
{
public int frequency;
public char c;
public Node left;
public Node right;
public Node()
{
//does Nothing
}
{
left = node1;
right = node2;
}
else
{
right = node1;
left = node2;
}
frequency = node1.frequency + node2.frequency;
return this;
}
}
Clase tree:
package huffmanexe;
/**
*
* @author franklin aimituma suyo
*/
public class tree extends Node
{
private Node root;
public tree()
{
root = null;
}
this.root.frequency = node.frequency;
this.root.c = node.c;
this.root.left = node.left;
this.root.right = node.right;
}
this.charArray = charArray;
for(i = 0; i < charArray.length; i++)
{
temp = search(rootNode, "", charArray[i]);
finalBitPattern += temp+" ";
System.out.println("Mis valores: "+charArray[i]+" = "+temp);
}
// System.out.println("My bit padre final: "+finalBitPattern);
}
else
{
if(valueL == "")
{
return search(rootNode.right, value+"1",myChar);
}
else
{
return valueL;
}
}
}
else
{
return "";
}
}
}
Clase Huffman:
package huffmanexe;
import java.util.*;
/**
* @author franklin aimituma suyo
*/
public class Huffman {
//
private static String value;
private static char charArray[];
//convertidor de string a caracteres
private static int table[] = new int[0x7f];
//mantiene la frecuencia del elemento
lengthOfTable = counter;
counter = 0;
myNode = new Node[lengthOfTable];
counter++;
}
}
lengthOfNode = myNode.length;
sort();
{
if(i+1 < lengthOfNode)
{
myTree = new tree(myNode[i], myNode[i+1]);
myNode[1] = myTree;
moveItems(i+1, lengthOfNode);
sort();
lengthOfNode -= 1;
i -= 1;
}
else
{
myNode[1] = myNode[1];//revisarlo..........
myNode[0] = new tree(myNode[0], myNode[1]);
}
}
}
catch(Exception e)
{
//I dare this program to crash...hahaha
}
}
return myNode[0];
}
catch(Exception e)
{
//
}
}
private static void sort()
{
Node temp;
for(int i = lengthOfNode-1; i > 1; i--)
{
for(int j = 0; j < i; j++)
{
if(myNode[j].frequency > myNode[j+1].frequency)
{
temp = myNode[j+1];
myNode[j+1] = myNode[j];
myNode[j] = temp;
}