编辑: 填充树的最佳方法是什么?我现在正在添加 10 个随机数
BinTree<int> myTree = new BinTree<int>();
int Value;
Console.WriteLine("Inserting Values: ");
Random random = new Random();
for (int i = 1; i <= 10; i++)
{
Value = random.Next(100);
Console.Write(Value + " ");
myTree.node(Value);
}
但
> myTree.node(Value);
不断出错,并显示“错误 1 'BINTREE.BinTree' 不包含 'node' 的定义,并且找不到接受类型 'BINTREE.BinTree' 的第一个参数的扩展方法 'node'(您是否缺少 using 指令或装配参考?)“
class BinTree<T> where T : IComparable
{
private NODE<T> root;
public BinTree()
{
root = null;
}
public BinTree(NODE<T> node)
{
root = node;
}
//order algorithms
public void PreOrder()
{
PREORDER(root);
}
private void PREORDER(NODE<T> tree)
{
if (tree != null)
{
Console.Write(tree.Data);
PREORDER(tree.Left);
PREORDER(tree.Right);
}
}
public void PostOrder()
{
POSTORDER(root);
}
private void POSTORDER(NODE<T> tree)
{
if (tree != null)
{
POSTORDER(tree.Left);
POSTORDER(tree.Right);
Console.WriteLine(tree.Data);
}
}
public void InOrder()
{
INORDER(root);
}
private void INORDER(NODE<T> tree)
{
if (tree != null)
{
INORDER(tree.Left);
Console.WriteLine(tree.Data);
INORDER(tree.Right);
}
}