Пример #1
0
        //Создание матрицы смежности и вывод в листбокс
        private void adjeClear(ReportForm reportForm)
        {
            AMatrix = new int[V.Count, V.Count];
            G.fillAdjacencyMatrix(V.Count, E, AMatrix);

            string sOut = V.Count + "";

            for (int i = 0; i < V.Count; i++)
            {
                sOut += /*(i + 1) +*/ " ";
            }
            reportForm.listBoxMatrix.Items.Add(sOut);
            for (int i = 0; i < V.Count; i++)
            {
                sOut = /*(i + 1)*/ "" /*+ " | "*/;
                for (int j = 0; j < V.Count; j++)
                {
                    sOut += AMatrix[i, j] + " ";
                }
                reportForm.listBoxMatrix.Items.Add(sOut);
            }
        }
Пример #2
0
        private void cohesion_Click(object sender, EventArgs e)
        {
            AMatrix = new int[V.Count, V.Count];
            G.fillAdjacencyMatrix(V.Count, E, AMatrix);

            if (V.Count == 0)
            {
                MessageBox.Show("Заполните граф!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int[] status = new int[V.Count];
            for (int i = 0; i < V.Count; i++)
            {
                status[i] = 0;
            }

            int curr = 0;

            status[curr] = 1; //Вершина с индексом 0 считается проиденнои
            Queue och = new Queue();

            och.Enqueue(curr);
            //Перемещаемся до тех пор, пока в очереди не останется ни однои вершины графа
            while (och.Count != 0)
            {
                curr = Convert.ToInt32(och.Dequeue());
                for (int j = 0; j < V.Count; j++)
                {
                    if (AMatrix[curr, j] != 0 && status[j] == 0)
                    {
                        status[j] = 1; //Посетили вершину
                        och.Enqueue(j);
                    }
                }
            }

            int finalCounter = 0;

            for (int i = 0; i < V.Count; i++)
            {
                if (status[i] == 1)
                {
                    finalCounter++;
                }
            }
            string res = "";

            if (finalCounter == V.Count)
            {
                res = "Граф является связным";
            }
            else
            {
                res = "Граф НЕ является связным";
            }
            ReportForm reportForm = new ReportForm();

            reportForm.listBoxMatrix.Items.Clear();

            reportForm.listBoxMatrix.Items.Add("Тема: Связность графа (#9)");
            reportForm.listBoxMatrix.Items.Add("Студент: Селютин Александр Дмитриевич");
            reportForm.listBoxMatrix.Items.Add("Группа: Б2-ИФСТ-31");
            reportForm.listBoxMatrix.Items.Add(DateTime.Now.ToString("yyyy-MM-dd"));
            reportForm.listBoxMatrix.Items.Add(DateTime.Now.ToString("HH:mm:ss"));
            reportForm.listBoxMatrix.Items.Add("Матрица смежности");
            adjeClear(reportForm);
            reportForm.listBoxMatrix.Items.Add("Результат: " + res);

            reportForm.Show();
        }