Exemplo n.º 1
0
        public void BuildSearch()
        {
            PointTree <T> beg = new PointTree <T>(Root.Data);

            MakeSearch(beg, Root);
            Root = beg;
        }
Exemplo n.º 2
0
 public Tree(params T[] arr)
 {
     Root = new PointTree <T>(arr[0]);
     for (int i = 1; i < arr.Length; i++)
     {
         Add(Root, arr[i]);
     }
 }
Exemplo n.º 3
0
 public void Run(PointTree <T> t)
 {
     if (t != null)
     {
         Run(t.left);
         Run(t.right);
     }
 }
Exemplo n.º 4
0
 public int TreeDeep(PointTree <T> root)
 {
     if (root == null)
     {
         return(0);
     }
     else
     {
         return(1 + Math.Max(TreeDeep(root.left), TreeDeep(root.right)));
     }
 }
Exemplo n.º 5
0
 private void MakeSearch(PointTree <T> search, PointTree <T> root)
 {
     if (root != null)
     {
         MakeSearch(search, root.left);
         if (!search.Data.Equals(root.Data))
         {
             Add(search, root.Data);
         }
         MakeSearch(search, root.right);
     }
 }
Exemplo n.º 6
0
 private void ShowTree(PointTree <T> p, int l)
 {
     if (p != null)
     {
         ShowTree(p.left, l + 3);
         for (int i = 0; i < l; i++)
         {
             Console.Write(" ");
         }
         Console.WriteLine(p.Data);
         ShowTree(p.right, l + 3);
     }
 }
Exemplo n.º 7
0
        //public PointTree<T> IdealTree(int size, PointTree<T> root,T[] elem)
        //{
        //    count = 0;
        //    PointTree<T> r;
        //    int nleft, nright;
        //    if (size == 0)
        //    {
        //        root = null;
        //        return root;
        //    }
        //    nleft = size / 2;
        //    nright = size - nleft - 1;
        //    r = new PointTree<T>(elem[count]);
        //    count++;
        //    for (int i = 0; i < size; i++)
        //    {
        //        r.left = IdealTree(nleft, r.left,elem);
        //        r.right = IdealTree(nright, r.right,elem);
        //    }
        //    return root;
        //}
        private PointTree <T> IdealTree(int size, params T[] arr)
        {
            PointTree <T> r;
            int           nl, nr;

            if (size == 0)
            {
                return(null);
            }
            nl = size / 2; nr = size - nl - 1;
            r  = new PointTree <T>(arr[count]);
            count++;
            r.left  = IdealTree(nl, arr);
            r.right = IdealTree(nr, arr);
            return(r);
        }
Exemplo n.º 8
0
        public void Add(PointTree <T> root, T str)
        {
            PointTree <T> p  = root;
            PointTree <T> r  = null;
            bool          ok = false;

            while (p != null && !ok)
            {
                r = p;
                if (str.Equals(p.Data))
                {
                    ok = true;
                }
                else
                if (str.CompareTo(p.Data) == -1)
                {
                    p = p.left;
                }
                else
                {
                    p = p.right;
                }
            }
            if (ok)
            {
                ;
            }
            else
            {
                PointTree <T> NewPoint = new PointTree <T>(str);

                if (str.CompareTo(r.Data) == -1)
                {
                    r.left = NewPoint;
                }
                else
                {
                    r.right = NewPoint;
                }
            }
        }
Exemplo n.º 9
0
        public IEnumerator <T> InOrderTraversal()
        {
            if (Root != null)
            {
                Stack <PointTree <T> > stack   = new Stack <PointTree <T> >();
                PointTree <T>          current = Root;
                bool goLeftNext = true;

                stack.Push(current);

                while (stack.Count > 0)
                {
                    if (goLeftNext)
                    {
                        while (current.left != null)
                        {
                            stack.Push(current);
                            current = current.left;
                        }
                    }

                    yield return(current.Data);

                    if (current.right != null)
                    {
                        current    = current.right;
                        goLeftNext = true;
                    }
                    else
                    {
                        current    = stack.Pop();
                        goLeftNext = false;
                    }
                }
            }
        }
Exemplo n.º 10
0
 public Tree(int i, params T[] arr)
 {
     count = 0;
     Root  = IdealTree(arr.Length, arr);
 }
Exemplo n.º 11
0
 public Tree(PointTree <T> t)
 {
     Root = t;
 }
Exemplo n.º 12
0
 public Tree()
 {
     Root = null;
 }
Exemplo n.º 13
0
 public Tree <T> Delete()
 {
     Root = null;
     Console.WriteLine("Коллекция удалена");
     return(this);
 }
Exemplo n.º 14
0
 public PointTree(T t)
 {
     Data  = t;
     left  = null;
     right = null;
 }
Exemplo n.º 15
0
 public PointTree()
 {
     Data  = default(T);
     left  = null;
     right = null;
 }