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; } } } }
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); }
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; } }