Tech Off Post

Single Post Permalink

View Thread: Ruby on Rails vs. ASP.NET Deathmatch!!!
  • User profile image
    wkempf

    The C# equivalent is pretty close, making both arguments for/against (at least for this specific example) a little off the base.

    IEnumberable<MyType> bfs(MyType e)
    {
       List<MyType> q = new ArrayList();
       e.Mark();
       yield return e;
       while (q.Count > 0)
       {
          object u = q[0];
          q.RemoveAt(0);
          foreach (MyType v in u.EdgeIterator())
          {
             if (!v.Marked)
             {
                v.Mark();
                yield return v;
                q.Add(v);
             }
          }
       }
    }

    foreach(MyType v in bfs(e))
    {
       Console.WriteLine(v);
    }

    Note: This was typed free form and may contain numerous errors, but it should illustrate the point.