コード例 #1
0
 public void createNodeList(Dictionary<char, double> rfdict)
 {
     this.nodes = new List<Node>();
     foreach (KeyValuePair<char, double> kvp in rfdict.OrderBy(key => key.Value))
     {
         Node test = new Node(kvp.Key, kvp.Value);
         this.nodes.Add(test);
     }
 }
コード例 #2
0
 public void addDictfromTree(Node current)
 {
     if (current == null) return;
     if (current.isSign == true)
     {
         this.dict.Add(current.character[0], current.code);
     }
     addDictfromTree(current.left);
     addDictfromTree(current.right);
 }
コード例 #3
0
 public void generateCode(string c, Node current)
 {
     if (current == null)
         return;
     if (current.left == null && current.right == null)
     {
         current.code = c;
         current.isSign = true;
         return;
     }
     generateCode(c + "0", current.left);
     generateCode(c + "1", current.right);
 }
コード例 #4
0
 public void createTree()
 {
     while (nodes.Count > 1)
     {
         this.nodes.Sort();
         Node node1 = nodes[0];
         this.nodes.RemoveAt(0);
         Node node2 = nodes[0];
         this.nodes.RemoveAt(0);
         Node parent = new Node(node1, node2);
         this.nodes.Add(parent);
     }
     root = nodes[0];
 }
コード例 #5
0
ファイル: Node.cs プロジェクト: mutefiRe/MultimediaProcessing
 public Node(Node node1, Node node2)
 {
     if (node1.rf < node2.rf)
     {
         this.left = node2;
         this.right = node1;
     }
     else
     {
         this.left = node1;
         this.right = node2;
     }
     this.rf = left.rf + right.rf;
     this.character = left.character + right.character;
     this.left.parent = this;
     this.right.parent = this;
 }
コード例 #6
0
        public void printTree(Node current)
        {
            if (current == null) return;
            if (current.isSign == true)
            {
                string test = current.character;

                Console.WriteLine("Char:\t" + test + "\nCode:\t" + current.code + "\n");
            }
            printTree(current.left);
            printTree(current.right);
        }