Exemple #1
0
        public HuffmanTree generateHuffmanTree()
        {
            HuffmanTree tree = new HuffmanTree();
            HuffmanNode parentNode, leftNode, rightNode;

            string inputFileContent           = getFileContent(this._inputFilePath);
            Dictionary <char, uint>     dict  = getCharAbsFrequency(inputFileContent);
            PriorityQueue <HuffmanNode> queue = initPriorityQueue(dict); // init

            while (queue.Count() > 1)                                    // tree
            {
                leftNode   = queue.Dequeue();
                rightNode  = queue.Dequeue();
                parentNode = new HuffmanNode(leftNode.data + rightNode.data, new char(), false);

                parentNode.leftChild  = leftNode;
                parentNode.rightChild = rightNode;
                queue.Enqueue(parentNode);
            }

            tree.root = queue.Dequeue();
            return(tree);
        }
        public int CompareTo(object obj)
        {
            HuffmanNode other = obj as HuffmanNode;

            return(this.data.CompareTo(other.data));
        }