当前位置: 代码迷 >> .NET分析设计 >> 递归调用改为循环解决办法
  详细解决方案

递归调用改为循环解决办法

热度:239   发布时间:2016-05-01 22:38:40.0
递归调用改为循环
我就是想把这个最上面的那个函数改成循环的,请问怎么改呢???在线等答案啊、、、、、 

public void DisplayArround(Pane currentPane)
        {
            if (currentPane.State == PaneState.Opened || currentPane.HasMine)
            {
                    return;
            }
            currentPane.Open();

            List<Pane> panes = this.GetAroundPanes(currentPane);
            foreach (Pane p in panes)
            {
                if (this.GetAroundMineCount(p) == 0)
                {
                    DisplayArround(p);
                }
                else
                {
                    if (p.State != PaneState.Opened && !currentPane.HasMine)
                    {
                        p.Open();
                    }
                }
            }
        }


 private List<Pane> GetAroundPanes(Pane pane)
        {
            List<Pane> result = new List<Pane>();
            int paneWidth = pane.Width;
            int paneHeight = pane.Height;
            foreach (Pane p in this.Controls)
            {
                if (p.Top == pane.Top && Math.Abs(pane.Left - p.Left) == paneWidth
                   ||
                    p.Left == pane.Left & Math.Abs(pane.Top - p.Top) == paneHeight
                   ||
                    Math.Abs(p.Top - pane.Top) == paneHeight && Math.Abs(pane.Left - p.Left) == paneWidth
                    )
                {
                    result.Add(p);
                }
            }
            return result;
        
        }


 public int GetAroundMineCount(Pane pane)
        {
            int mineCount = 0;
            List<Pane> panes=GetAroundPanes(pane);
            foreach (Pane p in panes)
           {
               if (p.HasMine==true)
               {
                   mineCount++;
               }
  相关解决方案