Generic Tree Data Structure

   public class TreeNode<T>
   {
      public TreeNode()
      {
         Children = new List<TreeNode<T>>();
      }

      public void AddChild(TreeNode<T> item)
      {
         item.Parent = this;
         Children.Add(item);
      }

      public List<TreeNode<T>> Children { get; set; }
      public TreeNode<T> Parent { get; set; }
      public T Data { get; set; }

      public bool IsLeaf
      {
         get { return !Children.Any(); }
      }
   }

 

posted @ 2013-05-14 18:20  chunchill  阅读(227)  评论(0编辑  收藏  举报