Example #1
0
 private TreeNode()
 {
     this.Key = "ROOT";
     this.Count = int.MaxValue;
     this.Code = null;
     this.Left = null;
     this.Right = null;
 }
Example #2
0
 public int nodeCompare(TreeNode a, TreeNode b)
 {
     if (a.Count > b.Count) {
         return 1;
     } else if (a.Count < b.Count) {
         return -1;
     } else {
         return 0;
     }
 }
Example #3
0
 public void codeRight(TreeNode right, string leftcode, string rightcode)
 {
     if (right == null) {
         return;
     } else {
         right.Code = rightcode;
         leftcode = "1" + leftcode;
         rightcode = "1" + rightcode ;
         codeLeft (right.Left, leftcode,rightcode);
         codeRight (right.Right, leftcode,rightcode);
     }
 }
Example #4
0
 public void codeLeft(TreeNode left, string leftcode, string rightcode)
 {
     if (left == null) {
         return;
     } else {
         left.Code = leftcode;
         leftcode = "0" + leftcode;
         rightcode = "0" + rightcode;
         codeLeft (left.Left, leftcode,rightcode);
         codeRight (left.Right, leftcode,rightcode);
     }
 }
Example #5
0
 public static TreeNode create(params Object[] plist)
 {
     if (plist == null) {
         return new TreeNode ();
     } else {
         TreeNode tree = new TreeNode ();
         tree.Key = (plist.Length > 0) ? ((plist [0] != null && plist [0] is String) ? (String)plist [0] : "ROOT") : "ROOT";
         tree.Count = (plist.Length > 1) ? ((plist [1] != null && plist [1] is Int32) ? (Int32)plist[1] : int.MaxValue) : int.MaxValue;
         tree.Left = (plist.Length > 2) ? ((plist[2] != null && plist[2] is TreeNode) ? (TreeNode)plist[2] : null) : null;
         tree.Right = (plist.Length > 3) ? ((plist[3] != null && plist[3] is TreeNode) ? (TreeNode)plist[3] : null) : null;
         return tree;
     }
 }
Example #6
0
        public static byte[] serial(TreeNode root)
        {
            List<byte> buffer = new List<byte>();
            IDictionary<String,int> tree = root.getAllPairs();
            foreach (KeyValuePair<String, int> kvp in tree)
            {
                try
                {
                    byte b = byte.Parse(kvp.Key);
                    Bit v = Bit.parse(kvp.Value.ToString());
                    buffer.Add(b);
                    buffer.AddRange(v.orginal);

                }
                finally
                {
                    ;
                }
            }
            return buffer.ToArray();
        }
Example #7
0
 public void editLeft(TreeNode left)
 {
     this.Left = left;
 }
Example #8
0
 private void mergeAllPairs(IDictionary<String, int> rs, TreeNode current)
 {
     if (current != null)
     {
         mergeAllPairs(rs, current.Left);
         rs.Add(current.Key,current.Count);
         mergeAllPairs(rs, current.Right);
     }
     else
     {
         return;
     }
 }
Example #9
0
 private void mergeAllKeys(IList<String> rs, TreeNode current)
 {
     if (current != null)
     {
         mergeAllKeys(rs, current.Left);
         rs.Add(current.Key);
         mergeAllKeys(rs, current.Right);
     }
     else
     {
         return;
     }
 }
Example #10
0
 private void mergeAllCount(IList<int> rs, TreeNode current)
 {
     if (current != null) {
         mergeAllCount (rs, current.Left);
         rs.Add (current.Count);
         mergeAllCount(rs, current.Right);
     }
     else
     {
         return;
     }
 }
Example #11
0
 public void editRight(TreeNode right)
 {
     this.Right = right;
 }