Exemple #1
0
 private static void GetVertex(Vertecx vertecx, Graff graff)
 {
     Console.Write($"{vertecx.Number}: ");
     foreach (var v in graff.GetVertexLists(vertecx))
     {
         Console.Write(v.Number + ", ");
     }
     Console.WriteLine();
 }
Exemple #2
0
        public List <Vertecx> GetVertexLists(Vertecx vertecx)
        {
            var result = new List <Vertecx>();

            foreach (var edge in Edges)
            {
                if (edge.From == vertecx)
                {
                    result.Add(edge.To);
                }
            }
            return(result);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var graff = new Graff();

            var v1 = new Vertecx(1);
            var v2 = new Vertecx(2);
            var v3 = new Vertecx(3);
            var v4 = new Vertecx(4);
            var v5 = new Vertecx(5);
            var v6 = new Vertecx(6);
            var v7 = new Vertecx(7);

            //создание вершин
            graff.AddVertext(v1);
            graff.AddVertext(v2);
            graff.AddVertext(v3);
            graff.AddVertext(v4);
            graff.AddVertext(v5);
            graff.AddVertext(v6);
            graff.AddVertext(v7);

            //создание ребр
            graff.AddEdge(v1, v2);
            graff.AddEdge(v1, v3);
            graff.AddEdge(v3, v4);
            graff.AddEdge(v2, v5);
            graff.AddEdge(v2, v6);
            graff.AddEdge(v6, v5);
            graff.AddEdge(v5, v6);

            GetMatrix(graff);

            Console.WriteLine();
            Console.WriteLine();

            GetVertex(v1, graff);
            GetVertex(v2, graff);
            GetVertex(v3, graff);
            GetVertex(v4, graff);
            GetVertex(v5, graff);
            GetVertex(v6, graff);
            GetVertex(v7, graff);

            Console.WriteLine(graff.Wave(v1, v5));
            Console.WriteLine(graff.Wave(v2, v4));

            Console.ReadLine();
        }
Exemple #4
0
        public bool Wave(Vertecx start, Vertecx finish)
        {
            var result = new List <Vertecx>();
            var list   = new List <Vertecx> {
                start
            };

            list.Add(start);

            for (int i = 0; i < list.Count; i++)
            {
                var vertex = list[i];
                foreach (var item in GetVertexLists(vertex))
                {
                    if (!list.Contains(item))
                    {
                        list.Add(item);
                    }
                }
            }
            return(list.Contains(finish));
        }
Exemple #5
0
 /// <summary>
 /// Ребро граффа
 /// </summary>
 /// <param name="from"> откуда</param>
 /// <param name="to">куда</param>
 /// <param name="weight">вес</param>
 public Edge(Vertecx from, Vertecx to, int weight = 1)
 {
     From   = from;
     To     = to;
     Weight = weight;
 }
Exemple #6
0
        public void AddEdge(Vertecx from, Vertecx to)
        {
            var edge = new Edge(from, to);

            Edges.Add(edge);
        }
Exemple #7
0
 public void AddVertext(Vertecx vertex)
 {
     Vertexes.Add(vertex);
 }