创建一个泛型类来实现一个二叉树。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();
}
} }
}
试试
这是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();
}
} }
}
解决方案 »
- winform 如何取得discuz!论坛的验证码,并显示在picturebox中
- C# Winfrom远程自动更新
- 100分求做一个小功能
- 谁能帮我写个函数
- 放分求一个XML遍历操作的最基础例子,谢谢大家!!
- 关于多线程的问题,100分,在线等
- DataGridVIew动态添加、删除、修改保存后提交数据
- 请教关于转换的问题
- 一个web控件的键盘事件问题,大家都来看看
- 如何在C#中引用DELPHI写的DLL。
- DataGrid绑定DataSet,使用CurrencyManager的addNew()后DataGrid焦点不能指向新增的行,请教高手指点。
- C#如何实现Object与byte[]的互相转换,在线等
指令或程序集引用?)
IComparable是System命名空间中的东西,你看看文件头部是否有using System这样的语句
error CS5001: 程序“c:\1.exe”不包含适合于入口点的静态“Main”方法
出现了这个报错