Пример #1
0
        private static int GetFamilyLevel(IGenealogy firstGenealogy, int maximum)
        {
            if (firstGenealogy == null)
            {
                return(0);
            }

            List <Pair <IGenealogy, int> > list = new List <Pair <IGenealogy, int> >();

            list.Add(new Pair <IGenealogy, int>(firstGenealogy, 0));

            int maxDepth = 0;

            int index = 0;

            while (index < list.Count)
            {
                Pair <IGenealogy, int> gene = list[index];
                index++;

                if (maxDepth < gene.Second)
                {
                    maxDepth = gene.Second;
                }

                if (maxDepth >= maximum)
                {
                    return(maxDepth);
                }

                if (gene.First.IChildren != null)
                {
                    foreach (IGenealogy child in gene.First.IChildren)
                    {
                        if (child == null)
                        {
                            continue;
                        }

                        list.Add(new Pair <IGenealogy, int>(child, gene.Second + 1));
                    }
                }
            }

            return(maxDepth);
        }
Пример #2
0
        private static int GetFamilyLevel(IGenealogy firstGenealogy, int maximum)
        {
            if (firstGenealogy == null) return 0;

            List<Pair<IGenealogy, int>> list = new List<Pair<IGenealogy, int>>();
            list.Add(new Pair<IGenealogy, int>(firstGenealogy, 0));

            int maxDepth = 0;

            int index = 0;
            while (index < list.Count)
            {
                Pair<IGenealogy, int> gene = list[index];
                index++;

                if (maxDepth < gene.Second)
                {
                    maxDepth = gene.Second;
                }

                if (maxDepth >= maximum)
                {
                    return maxDepth;
                }

                if (gene.First.IChildren != null)
                {
                    foreach (IGenealogy child in gene.First.IChildren)
                    {
                        if (child == null) continue;

                        list.Add(new Pair<IGenealogy, int>(child, gene.Second + 1));
                    }
                }
            }

            return maxDepth;
        }
Пример #3
0
 public static int GetFamilyLevel(IGenealogy firstGenealogy)
 {
     return GetFamilyLevel(firstGenealogy, int.MaxValue);
 }
Пример #4
0
 public static int GetFamilyLevel(IGenealogy firstGenealogy)
 {
     return(GetFamilyLevel(firstGenealogy, int.MaxValue));
 }