Exemplo n.º 1
0
        private void label1_Click(object sender, EventArgs e)
        {
            Point x = label1.PointToClient(Cursor.Position);

            if (mode)
            {
                if (ShouldIAdd(x))
                {
                    Console.WriteLine(x.X + "  " + x.Y);
                    nyjet.Add(x);
                    Pen       blackPen = new Pen(Color.Black, 1);
                    Rectangle rect     = new Rectangle(x.X - 25, x.Y - 25, 50, 50);
                    g.DrawEllipse(blackPen, rect);
                    g.DrawString((NrNyje + 1) + "", new System.Drawing.Font("Arial", 16),
                                 new System.Drawing.SolidBrush(System.Drawing.Color.Black), new Point(x.X - 10, x.Y - 10));
                    grafi.ShtoNyje();
                    NrNyje++;
                }
                else
                {
                    Console.WriteLine("EKZISTON");
                }
            }
            else
            {
                //Console.WriteLine(whichCircle(x));

                int NyjaId = whichCircle(x);
                if (NyjaId != -1)
                {
                    Point Nyja = nyjet[whichCircle(x)];
                    selectedNyjet.Add(Nyja);
                    selectedNyjet2.Add(NyjaId);
                    DrawCircle(Color.Red, Nyja, NyjaId);

                    if (selectedNyjet.Count == 2)
                    {
                        int[] lidhja = { selectedNyjet2[0], selectedNyjet2[1] };
                        lidhjet.Add(lidhja);

                        grafi.shtoDege(selectedNyjet2[0], selectedNyjet2[1]);

                        DrawLine(Color.Black, selectedNyjet[0], selectedNyjet[1]);
                        selectedNyjet.Clear();
                        selectedNyjet2.Clear();
                        DrawAll();
                    }
                }
            }
        }
        public Grafi DFS(int nyja)
        {
            visited[nyja] = true;
            List <int> a = grafi.G[nyja];

            for (int i = 0; i < a.Count; i++)
            {
                int adj = a[i];
                if (!visited[adj])
                {
                    DFSGrafi.shtoDege(nyja, adj);
                    DFS(adj);
                }
            }
            return(DFSGrafi);
        }
        public Boolean DegeValide(int nyja1, int nyja2)
        {
            if (grafi.G[nyja1].Count == 1)
            {
                return(true);
            }

            visited  = new Boolean[grafi.G.Count];
            DFSGrafi = new Grafi(grafi.getNrNyjeve());
            int c1 = DFS(nyja1).G.Count;

            grafi.LargoDegen(nyja1, nyja2);

            visited  = new Boolean[grafi.G.Count];
            DFSGrafi = new Grafi(grafi.getNrNyjeve());
            int c2 = DFS(nyja1).G.Count;

            grafi.shtoDege(nyja1, nyja2);

            return(!(c1 > c2));
        }
        public Grafi BFS(int nyja)
        {
            Queue <int> Q = new Queue <int>();

            discoverd[nyja] = true;
            Q.Enqueue(nyja);
            while (Q.Count > 0)
            {
                int v = Q.Dequeue();
                BFSGrafi.shtoDege(nyja, v);
                Console.WriteLine(v);
                for (int i = 0; i < grafi.G[v].Count; i++)
                {
                    int w = grafi.G[v][i];
                    if (!discoverd[w])
                    {
                        discoverd[w] = true;
                        Q.Enqueue(w);
                    }
                }
            }
            return(BFSGrafi);
        }