static void Main(string[] args) { int name = 1; Random rnd = new Random(); points[0] = new Point(9999, false, "A"); points[1] = new Point(9999, false, "B"); points[1].predPoint = points[0]; points[2] = new Point(9999, false, "C"); points[2].predPoint = points[1]; points[3] = new Point(9999, false, "D"); points[3].predPoint = points[2]; points[4] = new Point(9999, false, "E"); points[4].predPoint = points[2]; points[5] = new Point(9999, false, "D2"); points[5].predPoint = points[4]; points[6] = new Point(9999, false, "C2"); points[6].predPoint = points[0]; points[7] = new Point(9999, false, "E2"); points[7].predPoint = points[0]; points[8] = new Point(9999, false, "C3"); points[8].predPoint = points[7]; points[9] = new Point(9999, false, "D3"); points[9].predPoint = points[7]; rebra[0] = new Rebro(points[0], points[1], 2); rebra[1] = new Rebro(points[1], points[2], 1); rebra[2] = new Rebro(points[2], points[3], 5); rebra[3] = new Rebro(points[2], points[4], 1); rebra[4] = new Rebro(points[4], points[5], 3); rebra[5] = new Rebro(points[0], points[6], 5); rebra[6] = new Rebro(points[0], points[7], 7); rebra[7] = new Rebro(points[7], points[8], 1); rebra[8] = new Rebro(points[7], points[9], 3); BeginPoint = points[0]; DekstraAlgorim Deks = new DekstraAlgorim(points, rebra); Deks.AlgoritmRun(BeginPoint); Deks.OneStep(points[0]); Deks.MinPath1(points[3]); List <String> myList = PrintGrath.PrintAllPoints(Deks); List <String> myList2 = PrintGrath.PrintAllMinPaths(Deks); for (int i = 0; i < myList.Count; i++) { Console.WriteLine(myList[i]); } Console.WriteLine(); for (int i = 0; i < myList2.Count; i++) { Console.WriteLine(myList2[i]); } Console.ReadLine(); }
public static List <string> PrintAllPoints(DekstraAlgorim da) { List <string> retListOfPoints = new List <string>(); foreach (Point p in da.points) { retListOfPoints.Add(string.Format("point name={0}, point value={1}, predok={2}", p.Name, p.ValueMetka, p.predPoint.Name ?? "нет предка")); } return(retListOfPoints); }
public static List <string> PrintAllMinPaths(DekstraAlgorim da) { List <string> retListOfPointsAndPaths = new List <string>(); foreach (Point p in da.points) { if (p != da.BeginPoint) { string s = string.Empty; foreach (Point p1 in da.MinPath1(p)) { s += string.Format("{0} ", p1.Name); } retListOfPointsAndPaths.Add(string.Format("Point ={0},MinPath from {1} = {2}", p.Name, da.BeginPoint.Name, s)); } } return(retListOfPointsAndPaths); }