Exemplo n.º 1
0
 public void Sort(List <HuffmanNode> nodeList)
 {
     for (int i = 1; i <= nodeList.Count - 1; i++)
     {
         for (int j = 0; j < nodeList.Count - 1; j++)
         {
             if (nodeList[j + 1].frequency < nodeList[j].frequency)
             {
                 HuffmanNode temp = nodeList[j];
                 nodeList[j]     = nodeList[j + 1];
                 nodeList[j + 1] = temp;
             }
         }
     }
 }
Exemplo n.º 2
0
        public void setCodeToTheTree(string code, HuffmanNode Nodes)
        {
            if (Nodes == null)
            {
                return;
            }
            if (Nodes.leftTree == null && Nodes.rightTree == null)
            {
                Nodes.code = code;
                return;
            }

            setCodeToTheTree(code + "0", Nodes.leftTree);
            setCodeToTheTree(code + "1", Nodes.rightTree);
        }
Exemplo n.º 3
0
 public HuffmanNode(HuffmanNode node1, HuffmanNode node2)
 {
     code       = "";
     isLeaf     = false;
     parentNode = null;
     // JIS KI FREQUENCY ZIADA HIA WOH RIGHT P LAGEGA HMAESHA
     if (node1.frequency >= node2.frequency)
     {
         rightTree            = node1;
         leftTree             = node2;
         rightTree.parentNode = leftTree.parentNode = this;
         symbol    = node1.symbol + node2.symbol;
         frequency = node1.frequency + node2.frequency;
     }
     else if (node1.frequency < node2.frequency)
     {
         rightTree           = node2;
         leftTree            = node1;
         leftTree.parentNode = rightTree.parentNode = this;
         symbol    = node2.symbol + node1.symbol;
         frequency = node2.frequency + node1.frequency;
     }
 }