Esempio n. 1
0
        public void dfs()
        {
            MyPoint         first = vertices[0];
            Stack <MyPoint> S     = new Stack <MyPoint>();

            S.Push(vertices[0]);

            while (S.Where(r => r.white).ToList().Count != 0)
            {
                if (S.Peek().white)
                {
                    first = S.Peek();
                    var peek = S.Peek();
                    DrawPoint(peek, bitmapAll, pictureBoxAll, Color.Black);
                    S.Peek().white = false;
                    S.Pop();
                    Thread.Sleep(time);
                    var listSuppv1 = allEdges.FindAll(ed => ed.v1 == peek.Number).ToList();
                    var listSuppv2 = allEdges.FindAll(ed => ed.v2 == peek.Number).ToList();
                    foreach (var edge in listSuppv1)
                    {
                        if (vertices[edge.v2].white)
                        {
                            if (!S.Contains(vertices[edge.v2]))
                            {
                                S.Push(vertices[edge.v2]);
                            }
                        }
                        else
                        {
                            DrawLine(vertices[edge.v2], peek, Color.Black);
                        }
                    }
                    foreach (var edge in listSuppv2)
                    {
                        if (vertices[edge.v1].white)
                        {
                            if (!S.Contains(vertices[edge.v1]))
                            {
                                S.Push(vertices[edge.v1]);
                            }
                        }
                        else
                        {
                            DrawLine(vertices[edge.v1], peek, Color.Black);
                        }
                    }
                }
            }
            foreach (var item in vertices)
            {
                item.white = true;
            }
            if (InvokeRequired)
            {
                pictureBoxAll.Invoke(new Action(() => pictureBoxAll.Update()));
            }
            else
            {
                pictureBoxAll.Update();
            }
        }
Esempio n. 2
0
 private Point medium(MyPoint p1, MyPoint p2)
 {
     return(new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2));
 }