示例#1
0
        public void Test1()
        {
            // Arrange
            var graph = new Graph();

            graph.AddVertex(0); // a
            graph.AddVertex(1); // b
            graph.AddVertex(2); // c
            graph.AddVertex(3); // d

            // (a, b)
            // (a, c)
            graph.AddDirectedEdge(0, 1);
            graph.AddDirectedEdge(0, 2);

            // (b, c)
            graph.AddDirectedEdge(1, 2);

            // (c, d)
            graph.AddDirectedEdge(2, 3);

            // Act
            var sortedVertices = Topo.TopologicalSort(graph);

            // Assert
            CollectionAssert.AreEqual(new[] { 3, 2, 1, 0 }, sortedVertices);
        }
示例#2
0
        static void Main(string[] args)
        {
            var topo = new Topo();

            topo.Sort();
        }