Ejemplo n.º 1
0
 public void MergeTree()
 {
     if (first != null)
     {
         if (first.link != null)
         {
             HuffmanTree aTemp   = RemoveTree();
             HuffmanTree bTemp   = RemoveTree();
             HuffmanTree sumTemp = new HuffmanTree("x");
             sumTemp.SetLeftChild(aTemp);
             sumTemp.SetRightChild(bTemp);
             sumTemp.SetFreq(aTemp.GetFreq() + bTemp.GetFreq());
             InsertTree(sumTemp);
         }
     }
 }
Ejemplo n.º 2
0
        public void InsertTree(HuffmanTree hTemp)
        {
            Node eTemp = new Node(hTemp);

            if (first == null)
            {
                first = eTemp;
            }
            else
            {
                Node p = first;
                while (p.link != null)
                {
                    if ((p.data.GetFreq() <= hTemp.GetFreq()) && (p.link.data.GetFreq() >= hTemp.GetFreq()))
                    {
                        break;
                    }
                    p = p.link;
                }
                eTemp.link = p.link;
                p.link     = eTemp;
            }
        }