Пример #1
0
        static void Main(string[] args)
        {
            var list = new AdjazenzList();

            list.Vertices.Add(AdjazenzListElement.create(1, 2, 6));
            list.Vertices.Add(AdjazenzListElement.create(3));
            list.Vertices.Add(AdjazenzListElement.create(0, 3, 4));
            list.Vertices.Add(AdjazenzListElement.create(6));
            list.Vertices.Add(AdjazenzListElement.create(0, 5, 8));
            list.Vertices.Add(AdjazenzListElement.create(2, 3, 4, 7));
            list.Vertices.Add(AdjazenzListElement.create(7));
            list.Vertices.Add(AdjazenzListElement.create(3, 8));
            list.Vertices.Add(AdjazenzListElement.create(5));

            var graph = new Graph(list);

            graph.PrintBFSPath(0);
            graph.PrintDFSPath(0);
        }
Пример #2
0
Файл: Graph.cs Проект: wobu/OTH
        public static AdjazenzListElement create(params int[] vertices)
        {
            if (vertices.Length == 0)
            {
                return(null);
            }
            else
            {
                var first   = new AdjazenzListElement();
                var current = first;

                for (int i = 0; i < vertices.Length; i++)
                {
                    current.Vertice = vertices[i];
                    if ((i + 1) < vertices.Length)
                    {
                        current.Next = new AdjazenzListElement();
                        current      = current.Next;
                    }
                }

                return(first);
            }
        }