创建一个泛型类来实现一个二叉树。Tree<T>提供了BuildInsert泛型方法用于在树中添加各种类型的数据项。然后构造一个实例,由字符构成的树
试试
这是yizhixiaozhu(师太,老衲受不了了) 的例子,我还是没有调试过去,能告诉我调试时候注意什么么
我运行csc 提示
1.CS(7,36): error CS0246: 找不到类型或命名空间名称“IComparable”(是否缺少 using
        指令或程序集引用?)
namespace BinaryTree
{
    /// <summary>
    /// 二叉树排序
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Tree<T> where T : IComparable<T>
    {
        T data;
        Tree<T> left;
        Tree<T> right;        public Tree(T nodeValue)
        {
            this.data = nodeValue;
            this.left = null;
            this.right = null;
        }        public T NodeData
        {
            get { return this.data; }
            set { this.data = value; }
        }        public Tree<T> LeftTree
        {
            get { return this.left; }
            set { this.left = value; }
        }        public Tree<T> RightTree
        {
            get { return this.right; }
            set { this.right = value; }
        }        /// <summary>
        /// 插入一个数据
        /// </summary>
        /// <param name="newItem"></param>
        public void Insert(T newItem)
        {
            T currentNodeValue = this.NodeData;
            if (currentNodeValue.CompareTo(newItem) > 0)
            {
                if (this.LeftTree == null)
                {
                    this.LeftTree = new Tree<T>(newItem);
                }
                else
                {
                    this.LeftTree.Insert(newItem);
                }
            }
            else 
            {
                if (this.RightTree == null)
                {                    this.RightTree = new Tree<T>(newItem);
                }
                else 
                {
                    this.RightTree.Insert(newItem);
                }            }
        }        public void WalkTree()
        {
            if (this.LeftTree != null)
            {
                this.LeftTree.WalkTree();
            }
            
            Console.WriteLine(this.NodeData.ToString());
            if (this.RightTree != null)
            {
                this.RightTree.WalkTree();
            }
        }    }
}

解决方案 »

  1.   

    小弟初学泛型,和.NET,愚昧之处,望请见谅
      

  2.   

    1.CS(7,36): error CS0246: 找不到类型或命名空间名称“IComparable”(是否缺少 using
            指令或程序集引用?)
    IComparable是System命名空间中的东西,你看看文件头部是否有using System这样的语句
      

  3.   

    我写进去了,但是还是不行啊
    error CS5001: 程序“c:\1.exe”不包含适合于入口点的静态“Main”方法
    出现了这个报错
      

  4.   

    你是用SDK编程吧,你这段代码相试验什么内容,添加一个静态的Main方法把你试验的代码弄进去啊