示例#1
0
        private static void topologicSorting(DirectedGraphMatrix originalGraph, List <int> retList, List <int> Done)
        {
            DirectedGraphMatrix graph = new DirectedGraphMatrix(1);

            graph.Set(originalGraph);

            while (retList.Count != originalGraph.NodesNr)
            {
                //find node with 0 dim
                for (int i = 0; i < graph.NodesNr; ++i)
                {
                    if (Done.Contains(i))
                    {
                        continue;
                    }

                    var neighbours = graph.GetNeighbours(i);

                    if (neighbours.Count == 0)
                    {
                        //remove this node
                        retList.Add(i);
                        Done.Add(i);
                        foreach (var node in graph.GetConnectedToNodes(i))
                        {
                            graph.RemoveConnection(node, i);
                        }
                    }
                }
            }
        }