Beispiel #1
0
        /// <summary>
        /// Ввод матрицы графа вручню с клавиатуры
        /// </summary>
        /// <returns></returns>
        public static GraphMatrix ManualCreate()
        {
            Console.Write("Введите количество элементов графа:");
            int         Size     = helper.CheckInput(true, true);
            GraphMatrix retValue = new GraphMatrix(Size);

            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    Console.Write("Введите элемент матрицы (" + i + ", " + j + " ):");
                    bool Ok  = true;
                    int  Inp = 0;
                    do
                    {
                        Inp = helper.CheckInput(true);
                        if (Inp == 0 || Inp == 1)
                        {
                            Ok = false;
                        }
                        else
                        {
                            Console.WriteLine("Ошибка значение элемента может быть либо 1 либо 0. Повторите ввод!");
                        }
                    }while (Ok);
                    retValue.Matrix[i, j] = Inp;
                }
            }
            return(retValue);
        }
Beispiel #2
0
        /// <summary>
        /// генератор матриц смежности по заданным размерам
        /// </summary>
        /// <returns></returns>
        public static GraphMatrix MatrixGenerator(int Size)
        {
            GraphMatrix retVal = new GraphMatrix(Size);
            Random      ran    = new Random();

            retVal.Matrix = BuildMatrix(Size, ran);
            return(retVal);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("1 - создание матрицы графа вручную");
            Console.WriteLine("2 - генерация матрицы графа случайно");
            int Inp = 0;

            do
            {
                Inp = helper.CheckInput(true, true);
                if (Inp == 1 || Inp == 2)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Ошибка ввода! Введите 1 либо 2");
                }
            } while (true);
            if (Inp == 1)
            {
                GraphMatrix NewMatrix = GraphMatrix.ManualCreate();
                Console.WriteLine("Вы создали граф в виде матрицы связанности:");
                NewMatrix.Show();

                int Comp = NewMatrix.ComponentConnected();
                Console.WriteLine("Вычисление компонента связанности графа: " + Comp);
            }
            else
            {
                Console.WriteLine("Введите количество вершин графа:");
                Inp = helper.CheckInput(true, true);
                GraphMatrix NewMatrix = GraphMatrix.MatrixGenerator(Inp);
                Console.WriteLine("Вы создали граф в виде матрицы связанности:");
                NewMatrix.Show();
                int Comp = NewMatrix.ComponentConnected();
                Console.WriteLine("Вычисление компонента связанности графа: " + Comp);
            }
            Console.ReadLine();
        }