예제 #1
0
파일: Forest.cs 프로젝트: TEnd321/Huffman2
 public void Print(HuffmanTree tree, TextWriter writer)
 {
     if (!tree.IsLeaf())
     {
         writer.Write("{0} ", tree.root.weight);
         writer.Flush();
     }
     else
     {
         writer.Write("*{0}:{1} ", tree.root.symbol, tree.root.weight);
         writer.Flush();
     }
     if (tree.root.Left != null)
     {
         Print(tree.root.Left, writer);
     }
     if (tree.root.Right != null)
     {
         Print(tree.root.Right, writer);
     }
 }
예제 #2
0
파일: Forest.cs 프로젝트: TEnd321/Huffman2
        /// <summary>
        /// Process forest, so only one tree will remain in list after funcion returns.
        /// </summary>
        public void CutDown()
        {
            while (forest.Count > 1)
            {
                forest.Sort();

                HuffmanTree newRoot = new HuffmanTree();
                HuffmanTree tree1   = forest[0];
                HuffmanTree tree2   = forest[1];

                tree1.root.Parent   = newRoot;
                tree2.root.Parent   = newRoot;
                newRoot.root.Left   = tree1;
                newRoot.root.Right  = tree2;
                newRoot.root.weight = tree2.root.weight + tree1.root.weight;
                newRoot.root.symbol = -1;

                forest.RemoveAt(0);
                forest.RemoveAt(0);

                forest.Add(newRoot);
            }
        }
예제 #3
0
 public Node(short symbol)
 {
     Left        = Right = Parent = null;
     this.symbol = symbol;
     weight      = 0;
 }
예제 #4
0
 public Node(short symbol, long weight)
 {
     Left        = Right = Parent = null;
     this.symbol = symbol;
     this.weight = weight;
 }
예제 #5
0
 public Node()
 {
     Left   = Right = Parent = null;
     weight = symbol = 0;
 }