예제 #1
0
        public Node GetRight()
        {
            if(right==null)
                right = new Node();

            return this.right;
        }
예제 #2
0
 public Node(int i, int v)
 {
     _index = i;
     value = v;
     left = null;
     right= null;
 }
예제 #3
0
        public Node GetLeft()
        {
            if (left == null)
                left = new Node();

            return this.left;
        }
예제 #4
0
        //zbiera liscie w kolejności od lewej poziomu "l" drzewa
        public void Collect(Node el, int l, ref StringBuilder ss)
        {
            if (el != null)
            {
                Collect(el.left, l, ref ss);
                Collect(el.right, l, ref ss);
                if (el.level == l)
                {
                    //for (int i = 0; i < treeDepth/(l+1); i++)
                    //{
                    //    ss.Append(" ");
                    //}
                    ss.Append(el.index.ToString());

                    //for (int i = 0; i < treeDepth; i++)
                    //{
                    //    ss.Append(" ");
                    //}
                }
                //else
                //{
                //      for (int i = 0; i <this.treeDepth* (l + 3) / (l + 5); i++)
                //    //for (int i = 0; i < this.treeDepth / (l + 2); i++)
                //        ss.Append(" ");
                //}
            }
            else ss.Append(" ");
        }
예제 #5
0
 public Node Get(Node elem, int i)
 {
     if (elem != null)
     {
         if (elem.index < i)
             elem = Get(elem.right, i);
         else if (elem.index > i)
             elem = Get(elem.left, i);
     }
     return elem;
 }
예제 #6
0
        public Node Insert(Node elem, int i, int val, int dep)
        {
            if (elem == null)
            {
                elem = new Node(i, val);
                elem.level = dep;
            }
            else if (elem.index < i)
                elem.right = Insert(elem.right, i, val, ++dep);
            else if (elem.index > i)
                elem.left = Insert(elem.left, i, val, ++dep);
            else
            {
                elem.value = val;
                return elem;
            }

            if (dep > this.treeDepth)
                treeDepth = dep;
            return elem;
        }
예제 #7
0
 // Left Visit Right, drukowanie infiksowe(in-order)
 public void Print(Node el)
 {
     if (el != null)
     {
         Print(el.left);
         Console.WriteLine(el.value+"\t"+el.index);
         Print(el.right);
     }
 }
예제 #8
0
 public Tree()
 {
     //root = new Node(0, v);
     root = null;
     treeDepth = 0;
 }