Esempio n. 1
0
        /// <summary>
        /// Load from an unsorted list.
        /// </summary>
        /// <param name="list"></param>
        public Tree(IEnumerable <Element> list, HasParent hasParent, IsParent isParent, IsEqual isEqual)
        {
            List <Element>        copy       = new List <Element>();
            IEnumerator <Element> enumerator = list.GetEnumerator();

            while (enumerator.MoveNext())
            {
                copy.Add(enumerator.Current);
            }

            LoadFromCopy(copy, hasParent, isParent, isEqual);
        }
Esempio n. 2
0
        public Tree(System.Collections.IEnumerable list, HasParent hasParent, IsParent isParent, IsEqual isEqual)
        {
            List <Element> copy = new List <Element>();

            System.Collections.IEnumerator enumerator = list.GetEnumerator();
            while (enumerator.MoveNext())
            {
                copy.Add((Element)enumerator.Current);
            }

            LoadFromCopy(copy, hasParent, isParent, isEqual);
        }
Esempio n. 3
0
        void LoadFromCopy(List <Element> copy, HasParent hasParent, IsParent isParent, IsEqual isEqual)
        {
            while (copy.Count > 0)
            {
                int i = 0;
                while (i < copy.Count)
                {
                    bool    fAdded = false;
                    Element f      = copy[i];
                    if (!hasParent(f))
                    {
                        mRoot.Children.Add(new Node <Element>(f));
                        fAdded = true;
                    }
                    else
                    {
                        IEnumerator <Node <Element> > innerenumerator = GetDepthFirstNodeEnumerator();
                        while (innerenumerator.MoveNext())
                        {
                            if (isParent(innerenumerator.Current.Data, f))
                            {
                                innerenumerator.Current.Children.Add(new Node <Element>(f));
                                fAdded = true;
                                break;
                            }
                        }
                    }

                    if (fAdded)
                    {
                        copy.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }