public int Solve(string source, string dest) { if (Dictionary.Where(s => s == source).Count() != 1) { throw new ArgumentException("source missing in dictionary"); } if (Dictionary.Where(s => s == dest).Count() != 1) { throw new ArgumentException("dest missing in dictionary"); } if (AdjGraph == null) // lazy init { AdjGraph = ConstructAdjancyGraph(Dictionary); } var data = GraphSearch.BFSTraversal <string>(AdjGraph, source); // print path Console.WriteLine(); Console.Write(dest); string parent = data[dest].ParentPath; while (string.IsNullOrEmpty(parent) == false) { Console.Write("->" + parent); parent = data[parent].ParentPath; } return(data[dest].Distance + 1); // including source node }
internal string Solve(string[] dependency) { Dictionary <string, List <string> > adjGraph = null; try { adjGraph = ComputeAdjGraph(dependency); } catch (Exception ex) { throw new ArgumentException("dependency", ex); } var result = GraphSearch.DFSTraversal <string>(adjGraph); return(string.Join(Seprator, result.OrderByDescending(s => s.Value.EndTime).Select(s => s.Key))); }