Ejemplo n.º 1
0
        private void generateChildNodes(treeNode tmpNode, Random rd)
        {
            count++;
            //Console.WriteLine(count);
            tmpNode.childNodeList = new List <treeNode>();
            for (int i = 0; i < 9; i++)
            {
                treeNode t = new treeNode();
                t.fNode = tmpNode;
                tmpNode.childNodeList.Add(t);
                t.xvalue = rd.Next(100);
            }
            int layer = Convert.ToInt16(textBox1.Text) - 1;

            if (layer < 0)
            {
                layer = 7;
            }
            foreach (treeNode t in tmpNode.childNodeList)
            {
                if (t.maxLayer() < layer)
                {
                    generateChildNodes(t, rd);
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Random rd = new Random();
            //long xd = 0;
            //for (int i = 0; i < 111111111; i++)
            //{

            //    int x = rd.Next(10000);
            //    //Console.WriteLine(i + "  " + x);
            //    xd += x;
            //}
            //Console.WriteLine(xd);


            count = 0;
            treeNode tmpNode = new treeNode();

            tmpNode.xvalue = 100000;



            generateChildNodes(tmpNode, new Random());

            //tmpNode.printself();
            Console.WriteLine("+++++++++++++++++=" + tmpNode.calculateSelf());
        }
Ejemplo n.º 3
0
 public int CompareTo(treeNode anotherNode)
 {
     if(weight > anotherNode.weight)
     {
         return 1;
     } else if (weight < anotherNode.weight)
     {
         return -1;
     }
     return 0;
 }
Ejemplo n.º 4
0
 public treeNode getFNode(treeNode t)
 {
     if (hasFNode(t))
     {
         t = t.fNode;
         return(getFNode(t));
     }
     else
     {
         return(t);
     }
 }
Ejemplo n.º 5
0
        public int maxLayer()
        {
            treeNode t = this;
            int      i = 0;

            while (hasFNode(t))
            {
                i++;
                t = t.fNode;
            }
            return(i);
        }
Ejemplo n.º 6
0
 public treeNode(treeNode leftNode, treeNode rightNode, int cammonWeight)
 {
     left = leftNode;
     right = rightNode;
     weight = cammonWeight;
 }
Ejemplo n.º 7
0
 private bool hasFNode(treeNode node)
 {
     return(node.fNode != null);
 }
Ejemplo n.º 8
0
 //default constructor
 public TreeClass(treeNode node)
 {
     leafNode = node;
     codesTable = new Dictionary<byte, string>();
 }
Ejemplo n.º 9
0
 private void createByteCodeTable(treeNode root, string startStr)
 {
     //if node doesn't have value
     if (root.value == null)
     {
         //and have left node
         if (root.left != null)
         {
             //add to output string '0'
             createByteCodeTable(root.left, startStr + "0");
         }
         //and have right node
         if (root.right != null)
         {
             //add to output string '1'
             createByteCodeTable(root.right, startStr + "1");
         }
     } else
     {
         //if node has value -> add for the key value output string calculated before
         codesTable[Convert.ToByte(root.value)] = startStr.ToString();
     }
 }