Huffman code Programfacing a trouble with this code
public class Node {HuffmanTree data;Node link;public Node(HuffmanTreenewData) {data=newData;}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class TreeList { public int count = 0; Node first; public void AddLetter( ) { HuffmanTree hTemp = new HuffmanTree(letter); Node eTemp = new Node(hTemp); if (first == null) first = eTemp; else { eTemp.link = first; first = eTemp; } count++; } public void SortTree() { TreeList otherList = new TreeList(); HuffmanTree aTemp; while (!(this.first == null)) { aTemp = this.RemoveTree(); otherList.InsertTree(aTemp); } this.first = otherList.first; } public void MergeTree() { 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; } return null; } 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; } count++; } public int Length() { return count; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class HuffmanTree { private HuffmanTree leftChild; private HuffmanTree rightChild; private string letter; private int freq; public HuffmanTree(string letter) { this.letter = letter; } public void SetLeftChild(HuffmanTree newChild) { leftChild = newChild; } public void SetRightChild(HuffmanTree newChild) { rightChild = newChild; } public void SetLetter(string newLetter) { letter = newLetter; } public void IncFreq() { freq++; } public void SetFreq(int newFreq) { freq = newFreq; } public HuffmanTree GetLeftChild() { return leftChild; } public HuffmanTree GetRightChild() { return rightChild; } public int GetFreq() { return freq; } }}