示例#1
0
        //kreiranje stabla iz liste cvorova
        public void CreateTree(List <HuffmanNode> nodesList)
        {
            while (nodesList.Count > 1)
            {
                HuffmanNode firstNode = nodesList[0];
                nodesList.RemoveAt(0);
                HuffmanNode secondNode = nodesList[0];
                nodesList.RemoveAt(0);
                nodesList.Add(new HuffmanNode(firstNode, secondNode));
                nodesList.Sort();
            }
            this.root = nodesList.First();

            SetCodesToTree(string.Empty, this.root);
        }
示例#2
0
        public void SetCodesToTree(string code, HuffmanNode root)
        {
            if (root == null)
            {
                return;
            }

            if (root.leftChild == null && root.rightChild == null)
            {
                this.compressionDict.Add(root.value, StringToBoolList(code));
                this.decompressionDict.Add(code, root.value);
                return;
            }

            SetCodesToTree(code + '0', root.leftChild);
            SetCodesToTree(code + '1', root.rightChild);
        }