Example #1
0
        // Решение зависимостей
        public static ArrayOfInt SolveDependences(ArrayOfArrayOfInt a)
        {
            ArrayOfInt b = new ArrayOfInt();

            while (true)
            {
                int solved = 0;
                for (int i = 0; i < a.Count; i++)
                {
                    if (!b.Contains(i) && IsFreeOfDependences(i, a, b))
                    {
                        solved++;
                        b.Add(i);
                    }
                }
                if (a.Count == b.Count)
                {
                    break;
                }
                else if (solved == 0)
                {
                    throw new Exception("Невозможно распутать зависимости!");
                }
            }
            return(b);
        }
Example #2
0
        public static bool IsFreeOfDependences(int x, ArrayOfArrayOfInt a, ArrayOfInt b)
        {
            int free = 0;

            for (int j = 0; j < a[x].Count; j++)
            {
                if (b.Contains(a[x, j]))
                {
                    free++;
                }
            }
            return(a[x].Count == free);
        }