Huffman code Program
facing a trouble with this code
i found it in book called data structures and algorithm in c# i wanna to make program to compress text with Huffman code algorithm and there is many errors in the code at the main of project and the methods first class
Code
public class Node {
HuffmanTree data;
Node link;
public Node(HuffmanTreenewData) {
data=newData;
}
}
2nd class
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespaceConsoleApplication1
{
classTreeList
{
publicint count = 0;
Node first;
publicvoidAddLetter()
{
HuffmanTree hTemp = new HuffmanTree(letter);
Node eTemp = new Node(hTemp);
if (first == null)
first = eTemp;
else
{
eTemp.link = first;
first = eTemp;
}
count++;
}
publicvoidSortTree()
{
TreeList otherList = new TreeList();
HuffmanTree aTemp;
while (!(this.first == null))
{
aTemp = this.RemoveTree();
otherList.InsertTree(aTemp);
}
this.first = otherList.first;
}
publicvoidMergeTree()
{
if (!(first == null))
if (!(first.link == null))
{
HuffmanTree aTemp = RemoveTree();
HuffmanTree bTemp = RemoveTree();
HuffmanTree sumTemp = new HuffmanTree(null);
sumTemp.SetLeftChild(aTemp);
sumTemp.SetRightChild(bTemp);
sumTemp.SetFreq(aTemp.GetFreq() +
bTemp.GetFreq());
InsertTree(sumTemp);
}
}
public HuffmanTree RemoveTree()
{
if (!(first == null))
{
HuffmanTree hTemp;
hTemp = first.data;
first = first.link;
count--;
return hTemp;
}
returnnull;
}
publicvoidInsertTree(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;
}
count++;
}
publicintLength()
{
return count;
}
}
}
jkjsha ahsa15 pointsPosted Dec 21, 2009, 9:47 AM EST